def test_parse_bad_config_file(self, save_user_config): fpath = os.path.abspath("dnstest.ini") contents = """ [servers] blarg """ self.write_conf_file(fpath, contents) dc = DnstestConfig() with pytest.raises(ParsingError): dc.load_config(fpath)
def test_parse_bad_config_file(self, save_user_config): fpath = os.path.abspath("dnstest.ini") contents = """ [servers] blarg """ self.write_conf_file(fpath, contents) dc = DnstestConfig() with pytest.raises(ParsingError): dc.load_config(fpath)
def test_parse_empty_config_file(self, save_user_config): dc = DnstestConfig() fpath = os.path.abspath("dnstest.ini") contents = "" self.write_conf_file(fpath, contents) dc.load_config(fpath) assert dc.server_prod == '' assert dc.server_test == '' assert dc.default_domain == '' assert dc.have_reverse_dns == True assert dc.ignore_ttl == False assert dc.sleep == 0.0
def test_parse_example_config_file(self, save_user_config): dc = DnstestConfig() fpath = os.path.abspath("dnstest.ini.example") dc.load_config(fpath) assert dc.server_prod == '1.2.3.4' assert dc.server_test == '1.2.3.5' assert dc.default_domain == '.example.com' assert dc.have_reverse_dns == True assert dc.ignore_ttl == False assert dc.sleep == 0.0 assert dc.asDict() == {'default_domain': '.example.com', 'have_reverse_dns': True, 'servers': {'prod': '1.2.3.4', 'test': '1.2.3.5'}, 'ignore_ttl': False, 'sleep': 0.0}
def test_parse_empty_config_file(self, save_user_config): dc = DnstestConfig() fpath = os.path.abspath("dnstest.ini") contents = "" self.write_conf_file(fpath, contents) dc.load_config(fpath) assert dc.server_prod == '' assert dc.server_test == '' assert dc.default_domain == '' assert dc.have_reverse_dns == True assert dc.ignore_ttl == False assert dc.sleep == 0.0
def test_parse_example_config_file(self, save_user_config): dc = DnstestConfig() fpath = os.path.abspath("dnstest.ini.example") dc.load_config(fpath) assert dc.server_prod == '1.2.3.4' assert dc.server_test == '1.2.3.5' assert dc.default_domain == '.example.com' assert dc.have_reverse_dns == True assert dc.ignore_ttl == False assert dc.sleep == 0.0 assert dc.asDict() == { 'default_domain': '.example.com', 'have_reverse_dns': True, 'servers': { 'prod': '1.2.3.4', 'test': '1.2.3.5' }, 'ignore_ttl': False, 'sleep': 0.0 }
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()
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()