diff options
Diffstat (limited to 'gitlint/tests')
-rw-r--r-- | gitlint/tests/base.py | 7 | ||||
-rw-r--r-- | gitlint/tests/cli/test_cli.py | 64 | ||||
-rw-r--r-- | gitlint/tests/config/test_config.py | 7 | ||||
-rw-r--r-- | gitlint/tests/contrib/rules/test_conventional_commit.py | 28 | ||||
-rw-r--r-- | gitlint/tests/expected/cli/test_cli/test_contrib_1 | 1 | ||||
-rw-r--r-- | gitlint/tests/expected/cli/test_cli/test_debug_1 | 4 | ||||
-rw-r--r-- | gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2 | 4 | ||||
-rw-r--r-- | gitlint/tests/expected/cli/test_cli/test_lint_commit_1 | 2 | ||||
-rw-r--r-- | gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2 | 4 | ||||
-rw-r--r-- | gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2 | 4 | ||||
-rw-r--r-- | gitlint/tests/expected/cli/test_cli/test_named_rules_2 | 4 | ||||
-rw-r--r-- | gitlint/tests/git/test_git_commit.py | 64 | ||||
-rw-r--r-- | gitlint/tests/rules/test_body_rules.py | 6 | ||||
-rw-r--r-- | gitlint/tests/rules/test_configuration_rules.py | 33 | ||||
-rw-r--r-- | gitlint/tests/rules/test_title_rules.py | 2 | ||||
-rw-r--r-- | gitlint/tests/rules/test_user_rules.py | 6 | ||||
-rw-r--r-- | gitlint/tests/test_options.py | 2 |
17 files changed, 224 insertions, 18 deletions
diff --git a/gitlint/tests/base.py b/gitlint/tests/base.py index 9406240..017122b 100644 --- a/gitlint/tests/base.py +++ b/gitlint/tests/base.py @@ -126,6 +126,10 @@ class BaseTestCase(unittest.TestCase): """ return super().assertRaisesRegex(expected_exception, re.escape(expected_regex), *args, **kwargs) + def clearlog(self): + """ Clears the log capture """ + self.logcapture.clear() + @contextlib.contextmanager def assertRaisesMessage(self, expected_exception, expected_msg): # pylint: disable=invalid-name """ Asserts an exception has occurred with a given error message """ @@ -182,3 +186,6 @@ class LogCapture(logging.Handler): def emit(self, record): self.messages.append(self.format(record)) + + def clear(self): + self.messages = [] diff --git a/gitlint/tests/cli/test_cli.py b/gitlint/tests/cli/test_cli.py index bf35e96..59ec7af 100644 --- a/gitlint/tests/cli/test_cli.py +++ b/gitlint/tests/cli/test_cli.py @@ -26,6 +26,7 @@ class CLITests(BaseTestCase): USAGE_ERROR_CODE = 253 GIT_CONTEXT_ERROR_CODE = 254 CONFIG_ERROR_CODE = 255 + GITLINT_SUCCESS_CODE = 0 def setUp(self): super(CLITests, self).setUp() @@ -180,6 +181,39 @@ class CLITests(BaseTestCase): self.assertEqual(stderr.getvalue(), expected) self.assertEqual(result.exit_code, 2) + @patch('gitlint.cli.get_stdin_data', return_value=False) + @patch('gitlint.git.sh') + def test_lint_commit(self, sh, _): + """ Test for --commit option """ + + sh.git.side_effect = [ + "6f29bf81a8322a04071bb794666e48c443a90360\n", # git log -1 <SHA> --pretty=%H + # git log --pretty <FORMAT> <SHA> + "test åuthor1\x00test-email1@föo.com\x002016-12-03 15:28:15 +0100\x00åbc\n" + "WIP: commït-title1\n\ncommït-body1", + "#", # git config --get core.commentchar + "commit-1-branch-1\ncommit-1-branch-2\n", # git branch --contains <sha> + "commit-1/file-1\ncommit-1/file-2\n", # git diff-tree + ] + + with patch('gitlint.display.stderr', new=StringIO()) as stderr: + result = self.cli.invoke(cli.cli, ["--commit", "foo"]) + self.assertEqual(result.output, "") + + self.assertEqual(stderr.getvalue(), self.get_expected("cli/test_cli/test_lint_commit_1")) + self.assertEqual(result.exit_code, 2) + + @patch('gitlint.cli.get_stdin_data', return_value=False) + @patch('gitlint.git.sh') + def test_lint_commit_negative(self, sh, _): + """ Negative test for --commit option """ + + # Try using --commit and --commits at the same time (not allowed) + result = self.cli.invoke(cli.cli, ["--commit", "foo", "--commits", "foo...bar"]) + expected_output = "Error: --commit and --commits are mutually exclusive, use one or the other.\n" + self.assertEqual(result.output, expected_output) + self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE) + @patch('gitlint.cli.get_stdin_data', return_value=u'WIP: tïtle \n') def test_input_stream(self, _): """ Test for linting when a message is passed via stdin """ @@ -283,6 +317,30 @@ class CLITests(BaseTestCase): "'--msg-filename' or when piping data to gitlint via stdin.\n")) @patch('gitlint.cli.get_stdin_data', return_value=False) + @patch('gitlint.git.sh') + def test_fail_without_commits(self, sh, _): + """ Test for --debug option """ + + sh.git.side_effect = [ + "", # First invocation of git rev-list + "" # Second invocation of git rev-list + ] + + with patch('gitlint.display.stderr', new=StringIO()) as stderr: + # By default, gitlint should silently exit with code GITLINT_SUCCESS when there are no commits + result = self.cli.invoke(cli.cli, ["--commits", "foo..bar"]) + self.assertEqual(stderr.getvalue(), "") + self.assertEqual(result.exit_code, cli.GITLINT_SUCCESS) + self.assert_log_contains("DEBUG: gitlint.cli No commits in range \"foo..bar\"") + + # When --fail-without-commits is set, gitlint should hard fail with code USAGE_ERROR_CODE + self.clearlog() + result = self.cli.invoke(cli.cli, ["--commits", "foo..bar", "--fail-without-commits"]) + self.assertEqual(result.output, 'Error: No commits in range "foo..bar"\n') + self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE) + self.assert_log_contains("DEBUG: gitlint.cli No commits in range \"foo..bar\"") + + @patch('gitlint.cli.get_stdin_data', return_value=False) def test_msg_filename(self, _): expected_output = "3: B6 Body message is missing\n" @@ -405,7 +463,7 @@ class CLITests(BaseTestCase): result = self.cli.invoke(cli.cli, ["--contrib", "contrib-title-conventional-commits,CC1"]) expected_output = self.get_expected('cli/test_cli/test_contrib_1') self.assertEqual(stderr.getvalue(), expected_output) - self.assertEqual(result.exit_code, 3) + self.assertEqual(result.exit_code, 2) @patch('gitlint.cli.get_stdin_data', return_value="Test tïtle\n") def test_contrib_negative(self, _): @@ -475,7 +533,7 @@ class CLITests(BaseTestCase): def test_generate_config(self, generate_config): """ Test for the generate-config subcommand """ result = self.cli.invoke(cli.cli, ["generate-config"], input="tëstfile\n") - self.assertEqual(result.exit_code, 0) + self.assertEqual(result.exit_code, self.GITLINT_SUCCESS_CODE) expected_msg = "Please specify a location for the sample gitlint config file [.gitlint]: tëstfile\n" + \ f"Successfully generated {os.path.realpath('tëstfile')}\n" self.assertEqual(result.output, expected_msg) @@ -517,7 +575,7 @@ class CLITests(BaseTestCase): result = self.cli.invoke(cli.cli, ["--commits", "master...HEAD"]) self.assert_log_contains("DEBUG: gitlint.cli No commits in range \"master...HEAD\"") - self.assertEqual(result.exit_code, 0) + self.assertEqual(result.exit_code, self.GITLINT_SUCCESS_CODE) @patch('gitlint.cli.get_stdin_data', return_value="WIP: tëst tïtle") def test_named_rules(self, _): diff --git a/gitlint/tests/config/test_config.py b/gitlint/tests/config/test_config.py index 93e35de..c3fd78a 100644 --- a/gitlint/tests/config/test_config.py +++ b/gitlint/tests/config/test_config.py @@ -50,6 +50,7 @@ class LintConfigTests(BaseTestCase): self.assertFalse(config.ignore_stdin) self.assertFalse(config.staged) + self.assertFalse(config.fail_without_commits) self.assertFalse(config.debug) self.assertEqual(config.verbosity, 3) active_rule_classes = tuple(type(rule) for rule in config.rules) @@ -95,6 +96,10 @@ class LintConfigTests(BaseTestCase): config.set_general_option("staged", "true") self.assertTrue(config.staged) + # fail-without-commits + config.set_general_option("fail-without-commits", "true") + self.assertTrue(config.fail_without_commits) + # target config.set_general_option("target", self.SAMPLES_DIR) self.assertEqual(config.target, self.SAMPLES_DIR) @@ -227,7 +232,7 @@ class LintConfigTests(BaseTestCase): # splitting which means it it will accept just about everything # invalid boolean options - for attribute in ['debug', 'staged', 'ignore_stdin']: + for attribute in ['debug', 'staged', 'ignore_stdin', 'fail_without_commits']: option_name = attribute.replace("_", "-") with self.assertRaisesMessage(LintConfigError, f"Option '{option_name}' must be either 'true' or 'false'"): diff --git a/gitlint/tests/contrib/rules/test_conventional_commit.py b/gitlint/tests/contrib/rules/test_conventional_commit.py index fb492df..5da5cd5 100644 --- a/gitlint/tests/contrib/rules/test_conventional_commit.py +++ b/gitlint/tests/contrib/rules/test_conventional_commit.py @@ -29,12 +29,34 @@ class ContribConventionalCommitTests(BaseTestCase): violations = rule.validate("bår: foo", None) self.assertListEqual([expected_violation], violations) + # assert violation when use strange chars after correct type + expected_violation = RuleViolation("CT1", "Title does not start with one of fix, feat, chore, docs," + " style, refactor, perf, test, revert, ci, build", + "feat_wrong_chars: föo") + violations = rule.validate("feat_wrong_chars: föo", None) + self.assertListEqual([expected_violation], violations) + + # assert violation when use strange chars after correct type + expected_violation = RuleViolation("CT1", "Title does not start with one of fix, feat, chore, docs," + " style, refactor, perf, test, revert, ci, build", + "feat_wrong_chars(scope): föo") + violations = rule.validate("feat_wrong_chars(scope): föo", 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'", "fix föo") violations = rule.validate("fix föo", None) self.assertListEqual([expected_violation], violations) + # assert no violation when use ! for breaking changes without scope + violations = rule.validate("feat!: föo", None) + self.assertListEqual([], violations) + + # assert no violation when use ! for breaking changes with scope + violations = rule.validate("fix(scope)!: föo", None) + self.assertListEqual([], violations) + # assert no violation when adding new type rule = ConventionalCommit({'types': ["föo", "bär"]}) for typ in ["föo", "bär"]: @@ -45,3 +67,9 @@ class ContribConventionalCommitTests(BaseTestCase): violations = rule.validate("fix: hür dur", None) expected_violation = RuleViolation("CT1", "Title does not start with one of föo, bär", "fix: hür dur") self.assertListEqual([expected_violation], violations) + + # assert no violation when adding new type named with numbers + rule = ConventionalCommit({'types': ["föo123", "123bär"]}) + for typ in ["föo123", "123bär"]: + violations = rule.validate(typ + ": hür dur", None) + self.assertListEqual([], violations) diff --git a/gitlint/tests/expected/cli/test_cli/test_contrib_1 b/gitlint/tests/expected/cli/test_cli/test_contrib_1 index ed21eca..b95433b 100644 --- a/gitlint/tests/expected/cli/test_cli/test_contrib_1 +++ b/gitlint/tests/expected/cli/test_cli/test_contrib_1 @@ -1,3 +1,2 @@ 1: CC1 Body does not contain a 'Signed-off-by' line -1: CT1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test, revert, ci, build: "Test tïtle" 1: CT1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "Test tïtle" diff --git a/gitlint/tests/expected/cli/test_cli/test_debug_1 b/gitlint/tests/expected/cli/test_cli/test_debug_1 index a95a58d..fcd5d7e 100644 --- a/gitlint/tests/expected/cli/test_cli/test_debug_1 +++ b/gitlint/tests/expected/cli/test_cli/test_debug_1 @@ -17,6 +17,7 @@ ignore-squash-commits: True ignore-revert-commits: True ignore-stdin: False staged: False +fail-without-commits: False verbosity: 1 debug: True target: {target} @@ -29,6 +30,9 @@ target: {target} regex=None I3: ignore-body-lines regex=None + I4: ignore-by-author-name + ignore=all + regex=None T1: title-max-length line-length=20 T2: title-trailing-whitespace diff --git a/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2 b/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2 index c05d147..7c94b45 100644 --- a/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2 +++ b/gitlint/tests/expected/cli/test_cli/test_input_stream_debug_2 @@ -17,6 +17,7 @@ ignore-squash-commits: True ignore-revert-commits: True ignore-stdin: False staged: False +fail-without-commits: False verbosity: 3 debug: True target: {target} @@ -29,6 +30,9 @@ target: {target} regex=None I3: ignore-body-lines regex=None + I4: ignore-by-author-name + ignore=all + regex=None T1: title-max-length line-length=72 T2: title-trailing-whitespace diff --git a/gitlint/tests/expected/cli/test_cli/test_lint_commit_1 b/gitlint/tests/expected/cli/test_cli/test_lint_commit_1 new file mode 100644 index 0000000..b9f0742 --- /dev/null +++ b/gitlint/tests/expected/cli/test_cli/test_lint_commit_1 @@ -0,0 +1,2 @@ +1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: commït-title1" +3: B5 Body message is too short (12<20): "commït-body1" diff --git a/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2 b/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2 index e8e9f33..f37ffa0 100644 --- a/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2 +++ b/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2 @@ -17,6 +17,7 @@ ignore-squash-commits: True ignore-revert-commits: True ignore-stdin: False staged: True +fail-without-commits: False verbosity: 3 debug: True target: {target} @@ -29,6 +30,9 @@ target: {target} regex=None I3: ignore-body-lines regex=None + I4: ignore-by-author-name + ignore=all + regex=None T1: title-max-length line-length=72 T2: title-trailing-whitespace diff --git a/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2 b/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2 index b822edc..1d1020a 100644 --- a/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2 +++ b/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2 @@ -17,6 +17,7 @@ ignore-squash-commits: True ignore-revert-commits: True ignore-stdin: False staged: True +fail-without-commits: False verbosity: 3 debug: True target: {target} @@ -29,6 +30,9 @@ target: {target} regex=None I3: ignore-body-lines regex=None + I4: ignore-by-author-name + ignore=all + regex=None T1: title-max-length line-length=72 T2: title-trailing-whitespace diff --git a/gitlint/tests/expected/cli/test_cli/test_named_rules_2 b/gitlint/tests/expected/cli/test_cli/test_named_rules_2 index 828e296..83c4bf2 100644 --- a/gitlint/tests/expected/cli/test_cli/test_named_rules_2 +++ b/gitlint/tests/expected/cli/test_cli/test_named_rules_2 @@ -17,6 +17,7 @@ ignore-squash-commits: True ignore-revert-commits: True ignore-stdin: False staged: False +fail-without-commits: False verbosity: 3 debug: True target: {target} @@ -29,6 +30,9 @@ target: {target} regex=None I3: ignore-body-lines regex=None + I4: ignore-by-author-name + ignore=all + regex=None T1: title-max-length line-length=72 T2: title-trailing-whitespace diff --git a/gitlint/tests/git/test_git_commit.py b/gitlint/tests/git/test_git_commit.py index 6bb545a..02c5795 100644 --- a/gitlint/tests/git/test_git_commit.py +++ b/gitlint/tests/git/test_git_commit.py @@ -75,11 +75,12 @@ class GitCommitTests(BaseTestCase): self.assertListEqual(sh.git.mock_calls, expected_calls) @patch('gitlint.git.sh') - def test_from_local_repository_specific_ref(self, sh): - sample_sha = "myspecialref" + def test_from_local_repository_specific_refspec(self, sh): + sample_refspec = "åbc123..def456" + sample_sha = "åbc123" sh.git.side_effect = [ - sample_sha, + sample_sha, # git rev-list <sample_refspec> "test åuthor\x00test-emåil@foo.com\x002016-12-03 15:28:15 +0100\x00åbc\n" "cömmit-title\n\ncömmit-body", "#", # git config --get core.commentchar @@ -87,10 +88,10 @@ class GitCommitTests(BaseTestCase): "foöbar\n* hürdur\n" ] - context = GitContext.from_local_repository("fåke/path", sample_sha) + context = GitContext.from_local_repository("fåke/path", refspec=sample_refspec) # assert that commit info was read using git command expected_calls = [ - call("rev-list", sample_sha, **self.expected_sh_special_args), + call("rev-list", sample_refspec, **self.expected_sh_special_args), call("log", sample_sha, "-1", "--pretty=%aN%x00%aE%x00%ai%x00%P%n%B", **self.expected_sh_special_args), call('config', '--get', 'core.commentchar', _ok_code=[0, 1], **self.expected_sh_special_args), call('diff-tree', '--no-commit-id', '--name-only', '-r', '--root', sample_sha, @@ -128,6 +129,59 @@ class GitCommitTests(BaseTestCase): self.assertListEqual(sh.git.mock_calls, expected_calls) @patch('gitlint.git.sh') + def test_from_local_repository_specific_commit_hash(self, sh): + sample_hash = "åbc123" + + sh.git.side_effect = [ + sample_hash, # git log -1 <sample_hash> + "test åuthor\x00test-emåil@foo.com\x002016-12-03 15:28:15 +0100\x00åbc\n" + "cömmit-title\n\ncömmit-body", + "#", # git config --get core.commentchar + "file1.txt\npåth/to/file2.txt\n", + "foöbar\n* hürdur\n" + ] + + context = GitContext.from_local_repository("fåke/path", commit_hash=sample_hash) + # assert that commit info was read using git command + expected_calls = [ + call("log", "-1", sample_hash, "--pretty=%H", **self.expected_sh_special_args), + call("log", sample_hash, "-1", "--pretty=%aN%x00%aE%x00%ai%x00%P%n%B", **self.expected_sh_special_args), + call('config', '--get', 'core.commentchar', _ok_code=[0, 1], **self.expected_sh_special_args), + call('diff-tree', '--no-commit-id', '--name-only', '-r', '--root', sample_hash, + **self.expected_sh_special_args), + call('branch', '--contains', sample_hash, **self.expected_sh_special_args) + ] + + # Only first 'git log' call should've happened at this point + self.assertEqual(sh.git.mock_calls, expected_calls[:1]) + + last_commit = context.commits[-1] + self.assertIsInstance(last_commit, LocalGitCommit) + self.assertEqual(last_commit.sha, sample_hash) + self.assertEqual(last_commit.message.title, "cömmit-title") + self.assertEqual(last_commit.message.body, ["", "cömmit-body"]) + self.assertEqual(last_commit.author_name, "test åuthor") + self.assertEqual(last_commit.author_email, "test-emåil@foo.com") + self.assertEqual(last_commit.date, datetime.datetime(2016, 12, 3, 15, 28, 15, + tzinfo=dateutil.tz.tzoffset("+0100", 3600))) + self.assertListEqual(last_commit.parents, ["åbc"]) + self.assertFalse(last_commit.is_merge_commit) + self.assertFalse(last_commit.is_fixup_commit) + self.assertFalse(last_commit.is_squash_commit) + self.assertFalse(last_commit.is_revert_commit) + + # First 2 'git log' calls should've happened at this point + self.assertListEqual(sh.git.mock_calls, expected_calls[:3]) + + self.assertListEqual(last_commit.changed_files, ["file1.txt", "påth/to/file2.txt"]) + # 'git diff-tree' should have happened at this point + self.assertListEqual(sh.git.mock_calls, expected_calls[:4]) + + self.assertListEqual(last_commit.branches, ["foöbar", "hürdur"]) + # All expected calls should've happened at this point + self.assertListEqual(sh.git.mock_calls, expected_calls) + + @patch('gitlint.git.sh') def test_get_latest_commit_merge_commit(self, sh): sample_sha = "d8ac47e9f2923c7f22d8668e3a1ed04eb4cdbca9" diff --git a/gitlint/tests/rules/test_body_rules.py b/gitlint/tests/rules/test_body_rules.py index a268585..812c74a 100644 --- a/gitlint/tests/rules/test_body_rules.py +++ b/gitlint/tests/rules/test_body_rules.py @@ -101,13 +101,13 @@ class BodyRuleTests(BaseTestCase): expected_violation = rules.RuleViolation("B5", "Body message is too short (21<120)", "å" * 21, 3) rule = rules.BodyMinLength({'min-length': 120}) - commit = self.gitcommit("Title\n\n%s\n" % ("å" * 21)) + commit = self.gitcommit("Title\n\n{0}\n".format("å" * 21)) # pylint: disable=consider-using-f-string violations = rule.validate(commit) self.assertListEqual(violations, [expected_violation]) # Make sure we don't get the error if the body-length is exactly the min-length rule = rules.BodyMinLength({'min-length': 8}) - commit = self.gitcommit("Tïtle\n\n%s\n" % ("å" * 8)) + commit = self.gitcommit("Tïtle\n\n{0}\n".format("å" * 8)) # pylint: disable=consider-using-f-string violations = rule.validate(commit) self.assertIsNone(violations) @@ -182,7 +182,7 @@ class BodyRuleTests(BaseTestCase): expected_violation = rules.RuleViolation("B7", "Body does not mention changed file 'föo/test.py'", None, 4) self.assertEqual([expected_violation], violations) - # assert multiple errors if multiple files habe changed and are not mentioned + # assert multiple errors if multiple files have changed and are not mentioned commit_msg = "This is å test\n\nHere is a mention of\nAnd here is a mention of" commit = self.gitcommit(commit_msg, ["föo/test.py", "bar.txt"]) violations = rule.validate(commit) diff --git a/gitlint/tests/rules/test_configuration_rules.py b/gitlint/tests/rules/test_configuration_rules.py index 479d9c2..9302da5 100644 --- a/gitlint/tests/rules/test_configuration_rules.py +++ b/gitlint/tests/rules/test_configuration_rules.py @@ -71,6 +71,39 @@ class ConfigurationRuleTests(BaseTestCase): "Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)', ignoring rules: T1,B2" self.assert_log_contains(expected_log_message) + def test_ignore_by_author_name(self): + commit = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line", author_name="Tëst nåme") + + # No regex specified -> Config shouldn't be changed + rule = rules.IgnoreByAuthorName() + config = LintConfig() + rule.apply(config, commit) + self.assertEqual(config, LintConfig()) + self.assert_logged([]) # nothing logged -> nothing ignored + + # Matching regex -> expect config to ignore all rules + rule = rules.IgnoreByAuthorName({"regex": "(.*)ëst(.*)"}) + expected_config = LintConfig() + expected_config.ignore = "all" + rule.apply(config, commit) + self.assertEqual(config, expected_config) + + expected_log_message = ("DEBUG: gitlint.rules Ignoring commit because of rule 'I4': " + "Commit Author Name 'Tëst nåme' matches the regex '(.*)ëst(.*)'," + " ignoring rules: all") + self.assert_log_contains(expected_log_message) + + # Matching regex with specific ignore + rule = rules.IgnoreByAuthorName({"regex": "(.*)nåme", "ignore": "T1,B2"}) + expected_config = LintConfig() + expected_config.ignore = "T1,B2" + rule.apply(config, commit) + self.assertEqual(config, expected_config) + + expected_log_message = ("DEBUG: gitlint.rules Ignoring commit because of rule 'I4': " + "Commit Author Name 'Tëst nåme' matches the regex '(.*)nåme', ignoring rules: T1,B2") + self.assert_log_contains(expected_log_message) + def test_ignore_body_lines(self): commit1 = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line") commit2 = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line") diff --git a/gitlint/tests/rules/test_title_rules.py b/gitlint/tests/rules/test_title_rules.py index e1be857..10b4aab 100644 --- a/gitlint/tests/rules/test_title_rules.py +++ b/gitlint/tests/rules/test_title_rules.py @@ -79,7 +79,7 @@ class TitleRuleTests(BaseTestCase): violations = rule.validate("This is å test", None) self.assertIsNone(violations) - # no violation if WIP occurs inside a wor + # no violation if WIP occurs inside a word violations = rule.validate("This is å wiping test", None) self.assertIsNone(violations) diff --git a/gitlint/tests/rules/test_user_rules.py b/gitlint/tests/rules/test_user_rules.py index 510a829..5bf9b77 100644 --- a/gitlint/tests/rules/test_user_rules.py +++ b/gitlint/tests/rules/test_user_rules.py @@ -97,7 +97,7 @@ class UserRuleTests(BaseTestCase): def test_assert_valid_rule_class(self): class MyLineRuleClass(rules.LineRule): id = 'UC1' - name = u'my-lïne-rule' + name = 'my-lïne-rule' target = rules.CommitMessageTitle def validate(self): @@ -105,14 +105,14 @@ class UserRuleTests(BaseTestCase): class MyCommitRuleClass(rules.CommitRule): id = 'UC2' - name = u'my-cömmit-rule' + name = 'my-cömmit-rule' def validate(self): pass class MyConfigurationRuleClass(rules.ConfigurationRule): id = 'UC3' - name = u'my-cönfiguration-rule' + name = 'my-cönfiguration-rule' def apply(self): pass diff --git a/gitlint/tests/test_options.py b/gitlint/tests/test_options.py index fc3ccc1..eabcfe1 100644 --- a/gitlint/tests/test_options.py +++ b/gitlint/tests/test_options.py @@ -197,7 +197,7 @@ class RuleOptionTests(BaseTestCase): self.assertEqual(option.value, self.get_sample_path()) # Expect exception if path type is invalid - option.type = u'föo' + option.type = 'föo' expected = "Option tëst-directory type must be one of: 'file', 'dir', 'both' (current: 'föo')" with self.assertRaisesMessage(RuleOptionError, expected): option.set("haha") |