Debian Codegraph @

qa/test_user_defined.py

raw symbols SCIP
1 from qa.base import BaseTestCase
2 from qa.shell import gitlint
3
4
5 class UserDefinedRuleTests(BaseTestCase):
6 """Integration tests for user-defined rules."""
7
8 def test_user_defined_rules_examples1(self):
9 """Test the user defined rules in the top-level `examples/` directory"""
10 extra_path = self.get_example_path()
11 commit_msg = "WIP: Thi$ is å title\nContent on the second line"
12 self.create_simple_commit(commit_msg)
13 output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5])
14 self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_examples_1"))
15
16 def test_user_defined_rules_examples2(self):
17 """Test the user defined rules in the top-level `examples/` directory"""
18 extra_path = self.get_example_path()
19 commit_msg = "Release: Thi$ is å title\nContent on the second line\n$This line is ignored \nThis isn't\t\n"
20 self.create_simple_commit(commit_msg)
21 output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5])
22 self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_examples_2"))
23
24 def test_user_defined_rules_examples_with_config(self):
25 """Test the user defined rules in the top-level `examples/` directory"""
26 extra_path = self.get_example_path()
27 commit_msg = "WIP: Thi$ is å title\nContent on the second line"
28 self.create_simple_commit(commit_msg)
29 output = gitlint(
30 "--extra-path",
31 extra_path,
32 "-c",
33 "body-max-line-count.max-line-count=1",
34 _cwd=self.tmp_git_repo,
35 _tty_in=True,
36 _ok_code=[6],
37 )
38 expected_path = "test_user_defined/test_user_defined_rules_examples_with_config_1"
39 self.assertEqualStdout(output, self.get_expected(expected_path))
40
41 def test_user_defined_rules_extra(self):
42 extra_path = self.get_sample_path("user_rules/extra")
43 commit_msg = "WIP: Thi$ is å title\nContent on the second line"
44 self.create_simple_commit(commit_msg)
45 output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[9])
46 self.assertEqualStdout(
47 output,
48 self.get_expected("test_user_defined/test_user_defined_rules_extra_1", {"repo-path": self.tmp_git_repo}),
49 )
50
51 def test_invalid_user_defined_rules(self):
52 extra_path = self.get_sample_path("user_rules/incorrect_linerule")
53 self.create_simple_commit("WIP: test")
54 output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[255])
55 self.assertEqualStdout(
56 output, "Config Error: User-defined rule class 'MyUserLineRule' must have a 'validate' method\n"
57 )