本文整理汇总了Python中pydnstest.config.DnstestConfig.to_string方法的典型用法代码示例。如果您正苦于以下问题:Python DnstestConfig.to_string方法的具体用法?Python DnstestConfig.to_string怎么用?Python DnstestConfig.to_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydnstest.config.DnstestConfig
的用法示例。
在下文中一共展示了DnstestConfig.to_string方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_example_config_to_string
# 需要导入模块: from pydnstest.config import DnstestConfig [as 别名]
# 或者: from pydnstest.config.DnstestConfig import to_string [as 别名]
def test_example_config_to_string(self):
""" test converting the example config to a string """
fpath = os.path.abspath("dnstest.ini.example")
with open(fpath, 'r') as fh:
expected = fh.read()
dc = DnstestConfig()
dc.server_prod = '1.2.3.4'
dc.server_test = '1.2.3.5'
dc.default_domain = '.example.com'
dc.have_reverse_dns = True
dc.ignore_ttl = False
dc.sleep = 0.0
result = dc.to_string()
assert result == expected
示例2: test_write
# 需要导入模块: from pydnstest.config import DnstestConfig [as 别名]
# 或者: from pydnstest.config.DnstestConfig import to_string [as 别名]
def test_write(self, save_user_config):
""" test writing the file to disk """
dc = DnstestConfig()
conf_str = dc.to_string()
mock_open = mock.mock_open()
if sys.version_info[0] == 3:
mock_target = 'builtins.open'
else:
mock_target = '__builtin__.open'
with mock.patch(mock_target, mock_open, create=True):
dc.write()
assert mock_open.call_count == 1
fh = mock_open.return_value.__enter__.return_value
assert fh.write.call_count == 1
assert fh.write.call_args == mock.call(conf_str)
示例3: main
# 需要导入模块: from pydnstest.config import DnstestConfig [as 别名]
# 或者: from pydnstest.config.DnstestConfig import to_string [as 别名]
def main(options):
"""
main function - does everything...
split this out this way for testing...p
"""
# read in config, set variable
config = DnstestConfig()
if options.exampleconf:
config.set_example_values()
print(config.to_string())
raise SystemExit(0)
if options.promptconfig:
# interactively build a configuration file
config.prompt_config()
raise SystemExit(0)
if options.config_file:
conf_file = options.config_file
else:
conf_file = config.find_config_file()
if conf_file is None:
print("ERROR: no configuration file found. Run with --promptconfig to build one interactively, or --example-config for an example.")
raise SystemExit(1)
config.load_config(conf_file)
if options.ignorettl:
config.ignore_ttl = True
if options.configprint:
print("# {fname}".format(fname=config.conf_file))
print(config.to_string())
raise SystemExit(0)
parser = DnstestParser()
chk = DNStestChecks(config)
if options.sleep:
config.sleep = options.sleep
print("Note - will sleep %g seconds between lines" % options.sleep)
# if no other options, read from stdin
if options.testfile:
if not os.path.exists(options.testfile):
print("ERROR: test file '%s' does not exist." % options.testfile)
raise SystemExit(1)
fh = open(options.testfile, 'r')
else:
# read from stdin
sys.stderr.write("WARNING: reading from STDIN. Run with '-f filename' to read tests from a file.\n")
fh = sys.stdin
# read input line by line, handle each line as we're given it
passed = 0
failed = 0
for line in fh:
line = line.strip()
if not line:
continue
if line[:1] == "#":
continue
if options.verify:
r = run_verify_line(line, parser, chk)
else:
r = run_check_line(line, parser, chk)
if r is False:
continue
elif r['result']:
passed = passed + 1
else:
failed = failed + 1
format_test_output(r)
if config.sleep is not None and config.sleep > 0.0:
sleep(config.sleep)
msg = ""
if failed == 0:
msg = "All %d tests passed. (pydnstest %s)" % (passed, VERSION)
else:
msg = "%d passed / %d FAILED. (pydnstest %s)" % (passed, failed, VERSION)
print("++++ %s" % msg)
if options.testfile:
# we were reading a file, close it
fh.close()