forked from jorisroovers/gitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_config.py
92 lines (73 loc) · 4.9 KB
/
test_config.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
import platform
import sys
import arrow
from sh import gitlint, git # pylint: disable=no-name-in-module
from qa.base import BaseTestCase
class ConfigTests(BaseTestCase):
""" Integration tests for gitlint configuration and configuration precedence. """
def test_ignore_by_id(self):
self._create_simple_commit(u"WIP: Thïs is a title.\nContënt on the second line")
output = gitlint("--ignore", "T5,B4", _tty_in=True, _cwd=self.tmp_git_repo, _ok_code=[1])
expected = u"1: T3 Title has trailing punctuation (.): \"WIP: Thïs is a title.\"\n"
self.assertEqual(output, expected)
def test_ignore_by_name(self):
self._create_simple_commit(u"WIP: Thïs is a title.\nContënt 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 = u"1: T3 Title has trailing punctuation (.): \"WIP: Thïs is a title.\"\n"
self.assertEqual(output, expected)
def test_verbosity(self):
self._create_simple_commit(u"WIP: Thïs is a title.\nContënt on the second line")
output = gitlint("-v", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
expected = u"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 = u"1: T3 Title has trailing punctuation (.)\n" + \
u"1: T5 Title contains the word 'WIP' (case-insensitive)\n" + \
u"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 = u"1: T3 Title has trailing punctuation (.): \"WIP: Thïs is a title.\"\n" + \
u"1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: Thïs is a title.\"\n" + \
u"2: B4 Second line is not empty: \"Contënt 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(u"This ïs a title.")
output = gitlint("-c", "title-max-length.line-length=5", _tty_in=True, _cwd=self.tmp_git_repo, _ok_code=[3])
expected = u"1: T1 Title exceeds max length (16>5): \"This ïs a title.\"\n" + \
u"1: T3 Title has trailing punctuation (.): \"This ïs a title.\"\n" + \
"3: B6 Body message is missing\n"
self.assertEqual(output, expected)
def test_config_from_file(self):
commit_msg = u"WIP: Thïs is a title thåt 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=[5])
expected = "1: T1 Title exceeds max length (42>20)\n" + \
"1: T5 Title contains the word 'WIP' (case-insensitive)\n" + \
u"1: T5 Title contains the word 'thåt' (case-insensitive)\n" + \
"2: B4 Second line is not empty\n" + \
"3: B1 Line exceeds max length (48>30)\n"
self.assertEqual(output, expected)
def test_config_from_file_debug(self):
commit_msg = u"WIP: Thïs is a title thåt 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)
commit_sha = self.get_last_commit_hash()
config_path = self.get_sample_path("config/gitlintconfig")
output = gitlint("--config", config_path, "--debug", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5])
expected_date = git("log", "-1", "--pretty=%ai", _cwd=self.tmp_git_repo)
expected_date = arrow.get(str(expected_date), "YYYY-MM-DD HH:mm:ss Z").datetime
expected_gitlint_version = gitlint("--version").replace("gitlint, version ", "").replace("\n", "")
expected_git_version = git("--version").replace("\n", "")
expected = self.get_expected('debug_output1', {'platform': platform.platform(), 'python_version': sys.version,
'git_version': expected_git_version,
'gitlint_version': expected_gitlint_version,
'config_path': config_path, 'target': self.tmp_git_repo,
'commit_sha': commit_sha, 'commit_date': expected_date})
self.assertEqual(output, expected)