def test_named_rules(self): # Store a copy of the default rules from the config, so we can reference it later config_builder = LintConfigBuilder() config = config_builder.build() default_rules = copy.deepcopy(config.rules) self.assertEqual(default_rules, config.rules) # deepcopy should be equal # Add a named rule by setting an option in the config builder that follows the named rule pattern # Assert that whitespace in the rule name is stripped rule_qualifiers = [u'T7:my-extra-rüle', u' T7 : my-extra-rüle ', u'\tT7:\tmy-extra-rüle\t', u'T7:\t\n \tmy-extra-rüle\t\n\n', "title-match-regex:my-extra-rüle"] for rule_qualifier in rule_qualifiers: config_builder = LintConfigBuilder() config_builder.set_option(rule_qualifier, 'regex', "föo") expected_rules = copy.deepcopy(default_rules) my_rule = rules.TitleRegexMatches({'regex': "föo"}) my_rule.id = rules.TitleRegexMatches.id + ":my-extra-rüle" my_rule.name = rules.TitleRegexMatches.name + ":my-extra-rüle" expected_rules._rules[u'T7:my-extra-rüle'] = my_rule self.assertEqual(config_builder.build().rules, expected_rules) # assert that changing an option on the newly added rule is passed correctly to the RuleCollection # we try this with all different rule qualifiers to ensure they all are normalized and map # to the same rule for other_rule_qualifier in rule_qualifiers: cb = config_builder.clone() cb.set_option(other_rule_qualifier, 'regex', other_rule_qualifier + "bōr") # before setting the expected rule option value correctly, the RuleCollection should be different self.assertNotEqual(cb.build().rules, expected_rules) # after setting the option on the expected rule, it should be equal my_rule.options['regex'].set(other_rule_qualifier + "bōr") self.assertEqual(cb.build().rules, expected_rules) my_rule.options['regex'].set("wrong")
def test_clone(self): config_builder = LintConfigBuilder() config_builder.set_option('general', 'verbosity', 2) config_builder.set_option('title-max-length', 'line-length', 100) expected = {'title-max-length': {'line-length': 100}, 'general': {'verbosity': 2}} self.assertDictEqual(config_builder._config_blueprint, expected) # Clone and verify that the blueprint is the same as the original cloned_builder = config_builder.clone() self.assertDictEqual(cloned_builder._config_blueprint, expected) # Modify the original and make sure we're not modifying the clone (i.e. check that the copy is a deep copy) config_builder.set_option('title-max-length', 'line-length', 120) self.assertDictEqual(cloned_builder._config_blueprint, expected)