def test_set_general_option_negative(self): config = LintConfig() with self.assertRaisesRegexp(LintConfigError, "'foo' is not a valid gitlint option"): config.set_general_option("foo", "bar") # invalid verbosity incorrect_values = [-1, "foo"] for value in incorrect_values: expected_msg = r"Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format(value) with self.assertRaisesRegexp(LintConfigError, expected_msg): config.verbosity = value incorrect_values = [4] for value in incorrect_values: with self.assertRaisesRegexp(LintConfigError, "Option 'verbosity' must be set between 0 and 3"): config.verbosity = value # invalid ignore_merge_commits incorrect_values = [-1, 4, "foo"] for value in incorrect_values: with self.assertRaisesRegexp(LintConfigError, r"Option 'ignore-merge-commits' must be either 'true' or 'false'"): config.ignore_merge_commits = value # invalid debug with self.assertRaisesRegexp(LintConfigError, r"Option 'debug' must be either 'true' or 'false'"): config.debug = "foobar"
def test_set_general_option_negative(self): config = LintConfig() # Note that we should't test whether we can set unicode because python just doesn't allow unicode attributes with self.assertRaisesRegex(LintConfigError, "'foo' is not a valid gitlint option"): config.set_general_option("foo", u"bår") # try setting _config_path, this is a real attribute of LintConfig, but the code should prevent it from # being set with self.assertRaisesRegex( LintConfigError, "'_config_path' is not a valid gitlint option"): config.set_general_option("_config_path", u"bår") # invalid verbosity` incorrect_values = [-1, u"föo"] for value in incorrect_values: expected_msg = u"Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format( value) with self.assertRaisesRegex(LintConfigError, expected_msg): config.verbosity = value incorrect_values = [4] for value in incorrect_values: with self.assertRaisesRegex( LintConfigError, "Option 'verbosity' must be set between 0 and 3"): config.verbosity = value # invalid ignore_merge_commits incorrect_values = [-1, 4, u"föo"] for value in incorrect_values: with self.assertRaisesRegex( LintConfigError, "Option 'ignore-merge-commits' must be either 'true' or 'false'" ): config.ignore_merge_commits = value # invalid ignore -> not here because ignore is a ListOption which converts everything to a string before # splitting which means it it will accept just about everything # invalid debug with self.assertRaisesRegex( LintConfigError, "Option 'debug' must be either 'true' or 'false'"): config.debug = u"föobar" # extra-path has its own negative test # invalid target with self.assertRaisesRegex( LintConfigError, u"Option target must be an existing directory \(current value: 'föo/bar'\)" ): config.target = u"föo/bar"
def test_set_general_option_negative(self): config = LintConfig() # Note that we shouldn't test whether we can set unicode because python just doesn't allow unicode attributes with self.assertRaisesRegex(LintConfigError, "'foo' is not a valid gitlint option"): config.set_general_option("foo", u"bår") # try setting _config_path, this is a real attribute of LintConfig, but the code should prevent it from # being set with self.assertRaisesRegex(LintConfigError, "'_config_path' is not a valid gitlint option"): config.set_general_option("_config_path", u"bår") # invalid verbosity incorrect_values = [-1, u"föo"] for value in incorrect_values: expected_msg = u"Option 'verbosity' must be a positive integer (current value: '{0}')".format(value) with self.assertRaisesRegex(LintConfigError, expected_msg): config.verbosity = value incorrect_values = [4] for value in incorrect_values: with self.assertRaisesRegex(LintConfigError, "Option 'verbosity' must be set between 0 and 3"): config.verbosity = value # invalid ignore_xxx_commits ignore_attributes = ["ignore_merge_commits", "ignore_fixup_commits", "ignore_squash_commits", "ignore_revert_commits"] incorrect_values = [-1, 4, u"föo"] for attribute in ignore_attributes: for value in incorrect_values: option_name = attribute.replace("_", "-") with self.assertRaisesRegex(LintConfigError, "Option '{0}' must be either 'true' or 'false'".format(option_name)): setattr(config, attribute, value) # invalid ignore -> not here because ignore is a ListOption which converts everything to a string before # splitting which means it it will accept just about everything # invalid boolean options for attribute in ['debug', 'staged', 'ignore_stdin']: option_name = attribute.replace("_", "-") with self.assertRaisesRegex(LintConfigError, "Option '{0}' must be either 'true' or 'false'".format(option_name)): setattr(config, attribute, u"föobar") # extra-path has its own negative test # invalid target with self.assertRaisesRegex(LintConfigError, u"Option target must be an existing directory (current value: 'föo/bar')"): config.target = u"föo/bar"
def test_set_general_option(self): config = LintConfig() # Check that default general options are correct self.assertTrue(config.ignore_merge_commits) self.assertFalse(config.debug) self.assertEqual(config.verbosity, 3) active_rule_classes = [type(rule) for rule in config.rules] self.assertListEqual(active_rule_classes, config.default_rule_classes) # Check that we can change the general options # ignore config.set_general_option("ignore", "title-trailing-whitespace, B2") expected_ignored_rules = set([rules.BodyTrailingWhitespace, rules.TitleTrailingWhitespace]) active_rule_classes = set(type(rule) for rule in config.rules) # redetermine active rule classes expected_active_rule_classes = set(config.default_rule_classes) - expected_ignored_rules self.assertSetEqual(active_rule_classes, expected_active_rule_classes) # verbosity config.set_general_option("verbosity", 1) self.assertEqual(config.verbosity, 1) # ignore_merge_commit config.set_general_option("ignore-merge-commits", "false") self.assertFalse(config.ignore_merge_commits) # debug config.set_general_option("debug", "true") self.assertTrue(config.debug)
def test_set_general_option_negative(self): config = LintConfig() with self.assertRaisesRegex(LintConfigError, "'foo' is not a valid gitlint option"): config.set_general_option("foo", "bar") # try setting _config_path, this is a real attribute of LintConfig, but the code should prevent it from # being set with self.assertRaisesRegex(LintConfigError, "'_config_path' is not a valid gitlint option"): config.set_general_option("_config_path", "bar") # invalid verbosity` incorrect_values = [-1, "foo"] for value in incorrect_values: expected_msg = r"Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format(value) with self.assertRaisesRegex(LintConfigError, expected_msg): config.verbosity = value incorrect_values = [4] for value in incorrect_values: with self.assertRaisesRegex(LintConfigError, "Option 'verbosity' must be set between 0 and 3"): config.verbosity = value # invalid ignore_merge_commits incorrect_values = [-1, 4, "foo"] for value in incorrect_values: with self.assertRaisesRegex(LintConfigError, r"Option 'ignore-merge-commits' must be either 'true' or 'false'"): config.ignore_merge_commits = value # invalid ignore -> not here because ignore is a ListOption which converts everything to a string before # splitting which means it it will accept just about everything # invalid debug with self.assertRaisesRegex(LintConfigError, r"Option 'debug' must be either 'true' or 'false'"): config.debug = "foobar" # invalid extra-path with self.assertRaisesRegex(LintConfigError, r"Option extra-path must be an existing directory \(current value: 'foo/bar'\)"): config.extra_path = "foo/bar" # invalid target with self.assertRaisesRegex(LintConfigError, r"Option target must be an existing directory \(current value: 'foo/bar'\)"): config.target = "foo/bar"
def test_extra_path(self): config = LintConfig() config.set_general_option("extra-path", self.get_user_rules_path()) self.assertEqual(config.extra_path, self.get_user_rules_path()) actual_rule = config.rules.find_rule('UC1') self.assertTrue(actual_rule.is_user_defined) self.assertEqual(ustr(type(actual_rule)), "<class 'my_commit_rules.MyUserCommitRule'>") self.assertEqual(actual_rule.id, 'UC1') self.assertEqual(actual_rule.name, u'my-üser-commit-rule') self.assertEqual(actual_rule.target, None) expected_rule_option = options.IntOption('violation-count', 1, u"Number of violåtions to return") self.assertListEqual(actual_rule.options_spec, [expected_rule_option]) self.assertDictEqual(actual_rule.options, {'violation-count': expected_rule_option}) # reset value (this is a different code path) config.set_general_option("extra-path", self.SAMPLES_DIR) self.assertEqual(config.extra_path, self.SAMPLES_DIR) self.assertIsNone(config.rules.find_rule("UC1"))
def test_extra_path(self): config = LintConfig() config.set_general_option("extra-path", self.get_rule_rules_path()) self.assertEqual(config.extra_path, self.get_rule_rules_path()) actual_rule = config.get_rule('TUC1') self.assertTrue(actual_rule.user_defined) self.assertEqual(str(type(actual_rule)), "<class 'my_commit_rules.MyUserCommitRule'>") self.assertEqual(actual_rule.id, 'TUC1') self.assertEqual(actual_rule.name, 'my-user-commit-rule') self.assertEqual(actual_rule.target, None) expected_rule_option = IntOption('violation-count', 1, "Number of violations to return") self.assertListEqual(actual_rule.options_spec, [expected_rule_option]) self.assertDictEqual(actual_rule.options, {'violation-count': expected_rule_option}) # reset value (this is a different code path) config.set_general_option("extra-path", self.SAMPLES_DIR) self.assertEqual(config.extra_path, self.SAMPLES_DIR) self.assertIsNone(config.get_rule("TUC1"))
def test_set_general_option_negative(self): config = LintConfig() with self.assertRaisesRegexp(LintConfigError, "'foo' is not a valid gitlint option"): config.set_general_option("foo", "bar") # invalid verbosity incorrect_values = [-1, "foo"] for value in incorrect_values: expected_msg = r"Option 'verbosity' must be a positive integer \(current value: '{0}'\)".format(value) with self.assertRaisesRegexp(LintConfigError, expected_msg): config.verbosity = value incorrect_values = [4] for value in incorrect_values: with self.assertRaisesRegexp(LintConfigError, "Option 'verbosity' must be set between 0 and 3"): config.verbosity = value # invalid ignore_merge_commits incorrect_values = [-1, 4, "foo"] for value in incorrect_values: with self.assertRaisesRegexp(LintConfigError, r"Option 'ignore-merge-commits' must be either 'true' or 'false'"): config.ignore_merge_commits = value
def test_contrib(self): config = LintConfig() contrib_rules = ["contrib-title-conventional-commits", "CC1"] config.set_general_option("contrib", ",".join(contrib_rules)) self.assertEqual(config.contrib, contrib_rules) # Check contrib-title-conventional-commits contrib rule actual_rule = config.rules.find_rule( "contrib-title-conventional-commits") self.assertTrue(actual_rule.is_contrib) self.assertEqual(ustr(type(actual_rule)), "<class 'conventional_commit.ConventionalCommit'>") self.assertEqual(actual_rule.id, 'CT1') self.assertEqual(actual_rule.name, u'contrib-title-conventional-commits') self.assertEqual(actual_rule.target, rules.CommitMessageTitle) expected_rule_option = options.ListOption( "types", [ "fix", "feat", "chore", "docs", "style", "refactor", "perf", "test", "revert" ], "Comma separated list of allowed commit types.", ) self.assertListEqual(actual_rule.options_spec, [expected_rule_option]) self.assertDictEqual(actual_rule.options, {'types': expected_rule_option}) # Check contrib-body-requires-signed-off-by contrib rule actual_rule = config.rules.find_rule( "contrib-body-requires-signed-off-by") self.assertTrue(actual_rule.is_contrib) self.assertEqual(ustr(type(actual_rule)), "<class 'signedoff_by.SignedOffBy'>") self.assertEqual(actual_rule.id, 'CC1') self.assertEqual(actual_rule.name, u'contrib-body-requires-signed-off-by') # reset value (this is a different code path) config.set_general_option("contrib", "contrib-body-requires-signed-off-by") self.assertEqual( actual_rule, config.rules.find_rule("contrib-body-requires-signed-off-by")) self.assertIsNone( config.rules.find_rule("contrib-title-conventional-commits")) # empty value config.set_general_option("contrib", "") self.assertListEqual(config.contrib, [])
def test_set_general_option(self): config = LintConfig() # Check that default general options are correct self.assertTrue(config.ignore_merge_commits) self.assertEqual(config.verbosity, 3) active_rule_classes = [type(rule) for rule in config.rules] self.assertListEqual(active_rule_classes, config.default_rule_classes) # Check that we can change the general options # ignore config.set_general_option("ignore", "title-trailing-whitespace, B2") expected_ignored_rules = set([rules.BodyTrailingWhitespace, rules.TitleTrailingWhitespace]) active_rule_classes = set(type(rule) for rule in config.rules) # redetermine active rule classes expected_active_rule_classes = set(config.default_rule_classes) - expected_ignored_rules self.assertSetEqual(active_rule_classes, expected_active_rule_classes) # verbosity config.set_general_option("verbosity", 1) self.assertEqual(config.verbosity, 1) # ignore_merge_commit config.set_general_option("ignore-merge-commits", "false") self.assertFalse(config.ignore_merge_commits)
def test_set_general_option(self): config = LintConfig() # Check that default general options are correct self.assertTrue(config.ignore_merge_commits) self.assertTrue(config.ignore_fixup_commits) self.assertTrue(config.ignore_squash_commits) self.assertTrue(config.ignore_revert_commits) self.assertFalse(config.ignore_stdin) self.assertFalse(config.staged) self.assertFalse(config.debug) self.assertEqual(config.verbosity, 3) active_rule_classes = tuple(type(rule) for rule in config.rules) self.assertTupleEqual(active_rule_classes, config.default_rule_classes) # ignore - set by string config.set_general_option("ignore", "title-trailing-whitespace, B2") self.assertEqual(config.ignore, ["title-trailing-whitespace", "B2"]) # ignore - set by list config.set_general_option("ignore", ["T1", "B3"]) self.assertEqual(config.ignore, ["T1", "B3"]) # verbosity config.set_general_option("verbosity", 1) self.assertEqual(config.verbosity, 1) # ignore_merge_commit config.set_general_option("ignore-merge-commits", "false") self.assertFalse(config.ignore_merge_commits) # ignore_fixup_commit config.set_general_option("ignore-fixup-commits", "false") self.assertFalse(config.ignore_fixup_commits) # ignore_squash_commit config.set_general_option("ignore-squash-commits", "false") self.assertFalse(config.ignore_squash_commits) # ignore_revert_commit config.set_general_option("ignore-revert-commits", "false") self.assertFalse(config.ignore_revert_commits) # debug config.set_general_option("debug", "true") self.assertTrue(config.debug) # ignore-stdin config.set_general_option("ignore-stdin", "true") self.assertTrue(config.debug) # staged config.set_general_option("staged", "true") self.assertTrue(config.staged) # target config.set_general_option("target", self.SAMPLES_DIR) self.assertEqual(config.target, self.SAMPLES_DIR)
def test_set_general_option(self): config = LintConfig() # Check that default general options are correct self.assertTrue(config.ignore_merge_commits) self.assertFalse(config.debug) self.assertEqual(config.verbosity, 3) active_rule_classes = tuple(type(rule) for rule in config.rules) self.assertTupleEqual(active_rule_classes, config.default_rule_classes) # ignore - set by string config.set_general_option("ignore", "title-trailing-whitespace, B2") self.assertEqual(config.ignore, ["title-trailing-whitespace", "B2"]) # ignore - set by list config.set_general_option("ignore", ["T1", "B3"]) self.assertEqual(config.ignore, ["T1", "B3"]) # verbosity config.set_general_option("verbosity", 1) self.assertEqual(config.verbosity, 1) # ignore_merge_commit config.set_general_option("ignore-merge-commits", "false") self.assertFalse(config.ignore_merge_commits) # debug config.set_general_option("debug", "true") self.assertTrue(config.debug) # target config.set_general_option("target", self.SAMPLES_DIR) self.assertEqual(config.target, self.SAMPLES_DIR)