Example #1
0
    def test_delete_rules_by_attr(self):
        collection = RuleCollection()
        collection.add_rules(
            [rules.TitleMaxLength, rules.TitleTrailingWhitespace],
            {"foo": "bår"})
        collection.add_rules([rules.BodyHardTab], {"hur": "dûr"})

        # Assert all rules are there as expected
        self.assertEqual(len(collection), 3)
        for expected_rule in [
                rules.TitleMaxLength(),
                rules.TitleTrailingWhitespace(),
                rules.BodyHardTab()
        ]:
            self.assertEqual(collection.find_rule(expected_rule.id),
                             expected_rule)

        # Delete rules by attr, assert that we still have the right rules in the collection
        collection.delete_rules_by_attr("foo", "bår")
        self.assertEqual(len(collection), 1)
        self.assertIsNone(collection.find_rule(rules.TitleMaxLength.id), None)
        self.assertIsNone(
            collection.find_rule(rules.TitleTrailingWhitespace.id), None)

        found = collection.find_rule(rules.BodyHardTab.id)
        self.assertEqual(found, rules.BodyHardTab())
        self.assertEqual(found.hur, "dûr")
Example #2
0
    def test_get_rule(self):
        config = LintConfig()

        # get by id
        expected = rules.TitleMaxLength()
        rule = config.get_rule('T1')
        self.assertEqual(rule, expected)

        # get by name
        expected2 = rules.TitleTrailingWhitespace()
        rule = config.get_rule('title-trailing-whitespace')
        self.assertEqual(rule, expected2)

        # get non-existing
        rule = config.get_rule(u'föo')
        self.assertIsNone(rule)
Example #3
0
    def test_get_rule(self):
        config = LintConfig()

        # get by id
        expected = rules.TitleMaxLength()
        rule = config.get_rule('T1')
        self.assertEqual(rule, expected)

        # get by name
        expected = rules.TitleTrailingWhitespace()  # pylint: disable=redefined-variable-type
        rule = config.get_rule('title-trailing-whitespace')
        self.assertEqual(rule, expected)

        # get non-existing
        rule = config.get_rule('foo')
        self.assertIsNone(rule)
Example #4
0
    def test_add_find_rule(self):
        collection = RuleCollection()
        collection.add_rules([rules.TitleMaxLength, rules.TitleTrailingWhitespace], {"my_attr": u"föo"})

        # find by id
        expected = rules.TitleMaxLength()
        rule = collection.find_rule('T1')
        self.assertEqual(rule, expected)
        self.assertEqual(rule.my_attr, u"föo")

        # find by name
        expected2 = rules.TitleTrailingWhitespace()
        rule = collection.find_rule('title-trailing-whitespace')
        self.assertEqual(rule, expected2)
        self.assertEqual(rule.my_attr, u"föo")

        # find non-existing
        rule = collection.find_rule(u'föo')
        self.assertIsNone(rule)