本文整理汇总了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)
示例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
示例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'))
示例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
示例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'))