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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
from sh import gitlint # pylint: disable=no-name-in-module
from qa.base import BaseTestCase
class ConfigTests(BaseTestCase):
def test_ignore_by_code(self):
self._create_simple_commit("WIP: This is a title.\nContent on the second line")
output = gitlint("--ignore", "T5,B4", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[1])
expected = "1: T3 Title has trailing punctuation (.): \"WIP: This is a title.\"\n"
self.assertEqual(output, expected)
def test_ignore_by_name(self):
self._create_simple_commit("WIP: This is a title.\nContent on the second line")
output = gitlint("--ignore", "title-must-not-contain-word,body-first-line-empty",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[1])
expected = "1: T3 Title has trailing punctuation (.): \"WIP: This is a title.\"\n"
self.assertEqual(output, expected)
def test_verbosity(self):
self._create_simple_commit("WIP: This is a title.\nContent on the second line")
output = gitlint("-v", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
expected = "1: T3\n1: T5\n2: B4\n"
self.assertEqual(output, expected)
output = gitlint("-vv", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
expected = "1: T3 Title has trailing punctuation (.)\n" + \
"1: T5 Title contains the word 'WIP' (case-insensitive)\n" + \
"2: B4 Second line is not empty\n"
self.assertEqual(output, expected)
output = gitlint("-vvv", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
expected = "1: T3 Title has trailing punctuation (.): \"WIP: This is a title.\"\n" + \
"1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is a title.\"\n" + \
"2: B4 Second line is not empty: \"Content on the second line\"\n"
self.assertEqual(output, expected)
# test silent mode
output = gitlint("--silent", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
self.assertEqual(output, "")
def test_set_rule_option(self):
self._create_simple_commit("This is a title.")
output = gitlint("-c", "title-max-length.line-length=5", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
expected = "1: T1 Title exceeds max length (16>5): \"This is a title.\"\n" + \
"1: T3 Title has trailing punctuation (.): \"This is a title.\"\n" + \
"3: B6 Body message is missing\n"
self.assertEqual(output, expected)
def test_config_from_file(self):
commit_msg = "WIP: This is a title that is a bit longer.\nContent on the second line\n" + \
"This line of the body is here because we need it"
self._create_simple_commit(commit_msg)
config_path = self.get_sample_path("config/gitlintconfig")
output = gitlint("--config", config_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[4])
expected = "Using config from %s\n" % config_path + \
"1: T1 Title exceeds max length (42>20)\n" + \
"1: T5 Title contains the word 'WIP' (case-insensitive)\n" + \
"2: B4 Second line is not empty\n" + \
"3: B1 Line exceeds max length (48>30)\n"
# TODO(jroovers): test for trailing whitespace -> git automatically strips whitespace when passing
# taking a commit message via 'git commit -m'
self.assertEqual(output, expected)
|