當前位置: 首頁>>代碼示例>>Python>>正文


Python config.LintConfig類代碼示例

本文整理匯總了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()
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:35,代碼來源:test_hooks.py

示例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)
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:7,代碼來源:test_config.py

示例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)
開發者ID:tobyoxborrow,項目名稱:gitlint,代碼行數:30,代碼來源:test_config.py

示例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)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:8,代碼來源:test_config.py

示例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)
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:9,代碼來源:test_lint.py

示例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)
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:9,代碼來源:test_config.py

示例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)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:10,代碼來源:test_hooks.py

示例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)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:11,代碼來源:test_lint.py

示例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)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:11,代碼來源:test_hooks.py

示例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)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:12,代碼來源:test_config_builder.py

示例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
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:28,代碼來源:cli.py

示例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)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:14,代碼來源:test_lint.py

示例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
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:15,代碼來源:cli.py

示例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)
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:16,代碼來源:test_config.py

示例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)
開發者ID:jorisroovers,項目名稱:gitlint,代碼行數:16,代碼來源:test_config_builder.py


注:本文中的gitlint.config.LintConfig類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。