本文整理汇总了Python中gitlint.config.LintConfig类的典型用法代码示例。如果您正苦于以下问题:Python LintConfig类的具体用法?Python LintConfig怎么用?Python LintConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LintConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_uninstall_commit_msg_hook_negative
def test_uninstall_commit_msg_hook_negative(self, isdir, path_exists, remove):
lint_config = LintConfig()
lint_config.target = self.SAMPLES_DIR
# mock that the current directory is not a git repo
isdir.return_value = False
expected_msg = "{0} is not a git repository".format(self.SAMPLES_DIR)
with self.assertRaisesRegex(GitHookInstallerError, expected_msg):
GitHookInstaller.uninstall_commit_msg_hook(lint_config)
isdir.assert_called_with(os.path.join(self.SAMPLES_DIR, '.git/hooks'))
path_exists.assert_not_called()
remove.assert_not_called()
# mock that there is no commit hook present
isdir.return_value = True
path_exists.return_value = False
expected_dst = os.path.join(self.SAMPLES_DIR, COMMIT_MSG_HOOK_DST_PATH)
expected_msg = "There is no commit-msg hook present in {0}.".format(expected_dst)
with self.assertRaisesRegex(GitHookInstallerError, expected_msg):
GitHookInstaller.uninstall_commit_msg_hook(lint_config)
isdir.assert_called_with(os.path.join(self.SAMPLES_DIR, '.git/hooks'))
path_exists.assert_called_once_with(expected_dst)
remove.assert_not_called()
# mock that there is a different (=not gitlint) commit hook
isdir.return_value = True
path_exists.return_value = True
read_data = "#!/bin/sh\nfoo"
expected_dst = os.path.join(self.SAMPLES_DIR, COMMIT_MSG_HOOK_DST_PATH)
expected_msg = "The commit-msg hook in {0} was not installed by gitlint ".format(expected_dst) + \
r"\(or it was modified\).\nUninstallation of 3th party or modified gitlint hooks " + \
"is not supported."
with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True):
with self.assertRaisesRegex(GitHookInstallerError, expected_msg):
GitHookInstaller.uninstall_commit_msg_hook(lint_config)
remove.assert_not_called()
示例2: test_gitcontext_ignore_specific
def test_gitcontext_ignore_specific(self):
# ignore specific rules
config = LintConfig()
context = self.gitcontext("test\ngitlint-ignore: T1, body-hard-tab")
config.apply_config_from_commit(context.commits[-1])
expected_rules = [rule for rule in config.rules if rule.id not in ["T1", "body-hard-tab"]]
self.assertEqual(config.rules, expected_rules)
示例3: test_load_config_from_file_negative
def test_load_config_from_file_negative(self):
# bad config file load
foo_path = self.get_sample_path("foo")
with self.assertRaisesRegexp(LintConfigError, "Invalid file path: {0}".format(foo_path)):
LintConfig.load_from_file(foo_path)
# error during file parsing
path = self.get_sample_path("config/no-sections")
expected_error_msg = "File contains no section headers."
with self.assertRaisesRegexp(LintConfigError, expected_error_msg):
LintConfig.load_from_file(path)
# non-existing rule
path = self.get_sample_path("config/nonexisting-rule")
expected_error_msg = "No such rule 'foobar'"
with self.assertRaisesRegexp(LintConfigError, expected_error_msg):
LintConfig.load_from_file(path)
# non-existing option
path = self.get_sample_path("config/nonexisting-option")
expected_error_msg = "Rule 'title-max-length' has no option 'foobar'"
with self.assertRaisesRegexp(LintConfigError, expected_error_msg):
LintConfig.load_from_file(path)
# invalid option value
path = self.get_sample_path("config/invalid-option-value")
expected_error_msg = "'foo' is not a valid value for option 'title-max-length.line-length'. " + \
"Option 'line-length' must be a positive integer \(current value: 'foo'\)."
with self.assertRaisesRegexp(LintConfigError, expected_error_msg):
LintConfig.load_from_file(path)
示例4: test_ignore_independent_from_rules
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)
示例5: test_lint_sample4
def test_lint_sample4(self):
gitcontext = self.gitcontext(self.get_sample("commit_message/sample4"))
lintconfig = LintConfig()
lintconfig.apply_config_from_commit(gitcontext.commits[-1])
linter = GitLinter(lintconfig)
violations = linter.lint(gitcontext.commits[-1], gitcontext)
# expect no violations because sample4 has a 'gitlint: disable line'
expected = []
self.assertListEqual(violations, expected)
示例6: test_set_rule_option
def test_set_rule_option(self):
config = LintConfig()
# assert default title line-length
self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 72)
# change line length and assert it is set
config.set_rule_option('title-max-length', 'line-length', 60)
self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 60)
示例7: test_install_commit_msg_hook
def test_install_commit_msg_hook(self, isdir, path_exists, copy, stat, chmod):
lint_config = LintConfig()
lint_config.target = self.SAMPLES_DIR
expected_dst = os.path.join(self.SAMPLES_DIR, COMMIT_MSG_HOOK_DST_PATH)
GitHookInstaller.install_commit_msg_hook(lint_config)
isdir.assert_called_with(self.SAMPLES_DIR + '/.git/hooks')
path_exists.assert_called_once_with(expected_dst)
copy.assert_called_once_with(COMMIT_MSG_HOOK_SRC_PATH, expected_dst)
stat.assert_called_once_with(expected_dst)
chmod.assert_called_once_with(expected_dst, ANY)
示例8: test_lint_ignore
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)
示例9: test_uninstall_commit_msg_hook
def test_uninstall_commit_msg_hook(self, isdir, path_exists, remove):
lint_config = LintConfig()
lint_config.target = self.SAMPLES_DIR
read_data = "#!/bin/sh\n" + GITLINT_HOOK_IDENTIFIER
with patch('gitlint.hooks.open', mock_open(read_data=read_data), create=True):
GitHookInstaller.uninstall_commit_msg_hook(lint_config)
expected_dst = os.path.join(self.SAMPLES_DIR, COMMIT_MSG_HOOK_DST_PATH)
isdir.assert_called_with(os.path.join(self.SAMPLES_DIR, '.git/hooks'))
path_exists.assert_called_once_with(expected_dst)
remove.assert_called_with(expected_dst)
示例10: test_rebuild_config
def test_rebuild_config(self):
# normal config build
config_builder = LintConfigBuilder()
config_builder.set_option('general', 'verbosity', 3)
lint_config = config_builder.build()
self.assertEqual(lint_config.verbosity, 3)
# check that existing config changes when we rebuild it
existing_lintconfig = LintConfig()
existing_lintconfig.verbosity = 2
lint_config = config_builder.build(existing_lintconfig)
self.assertEqual(lint_config.verbosity, 3)
示例11: get_config
def get_config(ctx, target, config_path, c, ignore, verbose, silent):
""" 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:
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
# 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
示例12: test_lint_merge_commit
def test_lint_merge_commit(self):
commit = self.gitcommit(self.get_sample("commit_message/sample6")) # Sample 6 is a merge commit
lintconfig = LintConfig()
linter = GitLinter(lintconfig)
violations = linter.lint(commit)
# Even though there are a number of violations in the commit message, they are ignored because
# we are dealing with a merge commit
self.assertListEqual(violations, [])
# Check that we do see violations if we disable 'ignore-merge-commits'
lintconfig.ignore_merge_commits = False
linter = GitLinter(lintconfig)
violations = linter.lint(commit)
self.assertTrue(len(violations) > 0)
示例13: load_config_from_path
def load_config_from_path(ctx, config_path=None):
""" Tries loading the config from the given path. If no path is specified, the default config path
is tried, and if no file exists at the that location, None is returned. """
config = None
try:
if config_path:
config = LintConfig.load_from_file(config_path)
elif os.path.exists(DEFAULT_CONFIG_FILE):
config = LintConfig.load_from_file(DEFAULT_CONFIG_FILE)
except LintConfigError as e:
click.echo("Error during config file parsing: {0}".format(str(e)))
ctx.exit(CONFIG_ERROR_CODE)
return config
示例14: test_get_rule
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)
示例15: test_set_config_from_string_list
def test_set_config_from_string_list(self):
config = LintConfig()
# assert some defaults
self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 72)
self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 80)
self.assertEqual(config.verbosity, 3)
# change and assert changes
config_builder = LintConfigBuilder()
config_builder.set_config_from_string_list(['general.verbosity=1', 'title-max-length.line-length=60',
'body-max-line-length.line-length=120'])
config = config_builder.build()
self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 60)
self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 120)
self.assertEqual(config.verbosity, 1)