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


Python LintConfig.load_from_file方法代碼示例

本文整理匯總了Python中gitlint.config.LintConfig.load_from_file方法的典型用法代碼示例。如果您正苦於以下問題:Python LintConfig.load_from_file方法的具體用法?Python LintConfig.load_from_file怎麽用?Python LintConfig.load_from_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gitlint.config.LintConfig的用法示例。


在下文中一共展示了LintConfig.load_from_file方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_load_config_from_file_negative

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import load_from_file [as 別名]
    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,代碼行數:32,代碼來源:test_config.py

示例2: load_config_from_path

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import load_from_file [as 別名]
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,代碼行數:17,代碼來源:cli.py

示例3: test_load_config_from_file

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import load_from_file [as 別名]
    def test_load_config_from_file(self):
        # regular config file load, no problems
        config = LintConfig.load_from_file(self.get_sample_path("config/gitlintconfig"))

        # Do some assertions on the config
        self.assertEqual(config.verbosity, 1)
        self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 20)
        self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 30)
        self.assertIsNone(config.get_rule('title-trailing-whitespace'))
開發者ID:tobyoxborrow,項目名稱:gitlint,代碼行數:11,代碼來源:test_config.py

示例4: get_lint_config

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import load_from_file [as 別名]
def get_lint_config(config_path=None):
    """ Tries loading the config from the given path. If no path is specified, the default config path
    is tried, and if that is not specified, we the default config is returned. """
    # config path specified
    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(e.message))
        exit(CONFIG_ERROR_CODE)  # return 10000 on config error

    # no config file
    if config:
        click.echo("Using config from {0}".format(config.config_path))
    else:
        config = LintConfig()

    return config
開發者ID:tobyoxborrow,項目名稱:gitlint,代碼行數:24,代碼來源:cli.py

示例5: test_load_config_from_file

# 需要導入模塊: from gitlint.config import LintConfig [as 別名]
# 或者: from gitlint.config.LintConfig import load_from_file [as 別名]
    def test_load_config_from_file(self):
        # regular config file load, no problems
        config = LintConfig.load_from_file(self.get_sample_path("config/gitlintconfig"))

        # Do some assertions on the config
        self.assertEqual(config.verbosity, 1)
        self.assertFalse(config.ignore_merge_commits)

        # ignored rules
        expected_ignored_rules = set([rules.BodyTrailingWhitespace, rules.TitleTrailingWhitespace])
        active_rule_classes = set(type(rule) for rule in config.rules)
        self.assertSetEqual(set(config.default_rule_classes) - expected_ignored_rules, active_rule_classes)

        self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 20)
        self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 30)
        self.assertIsNone(config.get_rule('title-trailing-whitespace'))
開發者ID:cimarron-pistoncloud,項目名稱:gitlint,代碼行數:18,代碼來源:test_config.py


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