def test_extra_path_negative(self): config = LintConfig() regex = u"Option extra-path must be either an existing directory or file (current value: 'föo/bar')" # incorrect extra_path with self.assertRaisesRegex(LintConfigError, regex): config.extra_path = u"föo/bar" # extra path contains classes with errors with self.assertRaisesRegex(LintConfigError, "User-defined rule class 'MyUserLineRule' must have a 'validate' method"): config.extra_path = self.get_sample_path("user_rules/incorrect_linerule")
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_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" # invalid extra-path with self.assertRaisesRegexp( LintConfigError, r"Option extra_path must be an existing directory \(current value: 'foo/bar'\)" ): config.extra_path = "foo/bar"
def get_config(ctx, target, config_path, c, extra_path, ignore, verbose, silent, debug): """ Creates a LintConfig object based on a set of commandline parameters. """ try: # Config precedence: # First, load default config or config from configfile lint_config = load_config_from_path(ctx, config_path) # default to default configuration when no config file was loaded if lint_config: if debug: click.echo("Using config from {0}".format( lint_config.config_path)) else: lint_config = LintConfig() # Then process any commandline configuration flags lint_config.apply_config_options(c) # Finally, overwrite with any convenience commandline flags lint_config.apply_on_csv_string(ignore, lint_config.disable_rule) if silent: lint_config.verbosity = 0 elif verbose > 0: lint_config.verbosity = verbose if extra_path: lint_config.extra_path = extra_path if debug: lint_config.debug = True # Set target lint_config.target = target return lint_config except LintConfigError as e: click.echo("Config Error: {0}".format(str(e))) ctx.exit(CONFIG_ERROR_CODE) # return CONFIG_ERROR_CODE on config error