Exemplo n.º 1
0
    def test_ignore_by_title(self):
        commit = self.gitcommit("Releäse\n\nThis is the secōnd body line")

        # No regex specified -> Config shouldn't be changed
        rule = rules.IgnoreByTitle()
        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.IgnoreByTitle({"regex": "^Releäse(.*)"})
        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 'I1': " + \
            "Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: all"
        self.assert_log_contains(expected_log_message)

        # Matching regex with specific ignore
        rule = rules.IgnoreByTitle({
            "regex": "^Releäse(.*)",
            "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 'I1': " + \
            "Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: T1,B2"
Exemplo n.º 2
0
    def test_ignore_by_body(self):
        commit = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line")

        # No regex specified -> Config shouldn't be changed
        rule = rules.IgnoreByBody()
        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.IgnoreByBody({"regex": "(.*)relëase(.*)"})
        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 'I2': " + \
                               "Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)'," + \
                               " ignoring rules: all"
        self.assert_log_contains(expected_log_message)

        # Matching regex with specific ignore
        rule = rules.IgnoreByBody({
            "regex": "(.*)relëase(.*)",
            "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 'I2': " + \
            "Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)', ignoring rules: T1,B2"
        self.assert_log_contains(expected_log_message)
Exemplo n.º 3
0
 def test_ignore_independent_from_rules(self):
     # Test that the lintconfig rules are not modified when setting config.ignore
     # This was different in the past, this test is mostly here to catch regressions
     config = LintConfig()
     original_rules = config.rules
     config.ignore = ["T1", "T2"]
     self.assertEqual(config.ignore, ["T1", "T2"])
     self.assertSequenceEqual(config.rules, original_rules)
Exemplo n.º 4
0
 def test_ignore_independent_from_rules(self):
     # Test that the lintconfig rules are not modified when setting config.ignore
     # This was different in the past, this test is mostly here to catch regressions
     config = LintConfig()
     original_rules = config.rules
     config.ignore = ["T1", "T2"]
     self.assertEqual(config.ignore, ["T1", "T2"])
     self.assertListEqual(config.rules, original_rules)
Exemplo n.º 5
0
    def test_lint_ignore(self):
        lint_config = LintConfig()
        lint_config.ignore = ["T1", "T3", "T4", "T5", "T6", "B1", "B2"]
        linter = GitLinter(lint_config)
        violations = linter.lint(self.gitcommit(self.get_sample("commit_message/sample3")))

        expected = [RuleViolation("B4", "Second line is not empty", "This line should be empty", 2),
                    RuleViolation("B3", "Line contains hard tab characters (\\t)",
                                  "This line has a trailing tab.\t", 5)]

        self.assertListEqual(violations, expected)
Exemplo n.º 6
0
    def test_lint_ignore(self):
        lint_config = LintConfig()
        lint_config.ignore = ["T1", "T3", "T4", "T5", "T6", "B1", "B2"]
        linter = GitLinter(lint_config)
        violations = linter.lint(self.gitcommit(self.get_sample("commit_message/sample3")))

        expected = [RuleViolation("B4", "Second line is not empty", "This line should be empty", 2),
                    RuleViolation("B3", "Line contains hard tab characters (\\t)",
                                  u"This line has a tråiling tab.\t", 5)]

        self.assertListEqual(violations, expected)