1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# -*- coding: utf-8 -*-
from gitlint.tests.base import BaseTestCase
from gitlint.rules import RuleViolation
from gitlint.contrib.rules.conventional_commit import ConventionalCommit
from gitlint.config import LintConfig
class ContribConventionalCommitTests(BaseTestCase):
def test_enable(self):
# Test that rule can be enabled in config
for rule_ref in ['CT1', 'contrib-title-conventional-commits']:
config = LintConfig()
config.contrib = [rule_ref]
self.assertIn(ConventionalCommit(), config.rules)
def test_conventional_commits(self):
rule = ConventionalCommit()
# No violations when using a correct type and format
for type in ["fix", "feat", "chore", "docs", "style", "refactor", "perf", "test", "revert"]:
violations = rule.validate(type + u": föo", None)
self.assertListEqual([], violations)
# assert violation on wrong type
expected_violation = RuleViolation("CT1", "Title does not start with one of fix, feat, chore, docs,"
" style, refactor, perf, test, revert", u"bår: foo")
violations = rule.validate(u"bår: foo", None)
self.assertListEqual([expected_violation], violations)
# assert violation on wrong format
expected_violation = RuleViolation("CT1", "Title does not follow ConventionalCommits.org format "
"'type(optional-scope): description'", u"fix föo")
violations = rule.validate(u"fix föo", None)
self.assertListEqual([expected_violation], violations)
# assert no violation when adding new type
rule = ConventionalCommit({'types': [u"föo", u"bär"]})
for typ in [u"föo", u"bär"]:
violations = rule.validate(typ + u": hür dur", None)
self.assertListEqual([], violations)
# assert violation when using incorrect type when types have been reconfigured
violations = rule.validate(u"fix: hür dur", None)
expected_violation = RuleViolation("CT1", u"Title does not start with one of föo, bär", u"fix: hür dur")
self.assertListEqual([expected_violation], violations)
|