本文整理汇总了Python中twtxt.config.Config.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Config.from_file方法的具体用法?Python Config.from_file怎么用?Python Config.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twtxt.config.Config
的用法示例。
在下文中一共展示了Config.from_file方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_file
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import from_file [as 别名]
def test_from_file(config_dir):
with pytest.raises(ValueError) as e:
Config.from_file("invalid")
assert "Config file not found." in str(e.value)
with open(str(config_dir.join("empty")), "a") as fh:
fh.write("XXX")
with pytest.raises(ValueError) as e:
Config.from_file(str(config_dir.join("empty")))
assert "Config file is invalid." in str(e.value)
conf = Config.from_file(str(config_dir.join(Config.config_name)))
check_cfg(conf)
示例2: test_check_config_file_sanity
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import from_file [as 别名]
def test_check_config_file_sanity(capsys, config_dir):
with pytest.raises(ValueError) as e:
Config.from_file(str(config_dir.join("config_sanity")))
assert "Error in config file." in str(e.value)
out, err = capsys.readouterr()
for line in ["✗ Config error on limit_timeline - invalid literal for int() with base 10: '2t0'",
"✗ Config error on check_following - Not a boolean: TTrue",
"✗ Config error on porcelain - Not a boolean: Faltse",
"✗ Config error on disclose_identity - Not a boolean: Ftalse",
"✗ Config error on timeout - could not convert string to float: '5t.0'",
"✗ Config error on use_pager - Not a boolean: Falste",
"✗ Config error on use_cache - Not a boolean: Trute"]:
assert line in out
示例3: cli
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import from_file [as 别名]
def cli(ctx, config, verbose):
"""Decentralised, minimalist microblogging service for hackers."""
init_logging(debug=verbose)
try:
if config:
conf = Config.from_file(config)
else:
conf = Config.discover()
except ValueError:
click.echo("Error loading config file.")
if not config:
if click.confirm("Do you want to run the twtxt quickstart wizard?", abort=True):
pass
ctx.default_map = conf.build_default_map()
ctx.obj = {'conf': conf}
示例4: cli
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import from_file [as 别名]
def cli(ctx, config, verbose):
"""Decentralised, minimalist microblogging service for hackers."""
init_logging(debug=verbose)
if ctx.invoked_subcommand == "quickstart":
return
try:
if config:
conf = Config.from_file(config)
else:
conf = Config.discover()
except ValueError:
click.echo("✗ Config file not found or not readable. You may want to run twtxt quickstart.")
sys.exit()
ctx.default_map = conf.build_default_map()
ctx.obj = {'conf': conf}
示例5: cli
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import from_file [as 别名]
def cli(ctx, config, verbose):
"""Decentralised, minimalist microblogging service for hackers."""
init_logging(debug=verbose)
if ctx.invoked_subcommand == "quickstart":
return # Skip initializing config file
try:
if config:
conf = Config.from_file(config)
else:
conf = Config.discover()
except ValueError as e:
if "Error in config file." in str(e):
click.echo("✗ Please correct the errors mentioned above an run twtxt again.")
else:
click.echo("✗ Config file not found or not readable. You may want to run twtxt quickstart.")
sys.exit()
ctx.default_map = conf.build_default_map()
ctx.obj = {'conf': conf}