def test_setup_logging_with_file(): setup_logging.cache_clear() setup_logging("with_file") log = logging.getLogger("nosuch") assert len(log.handlers) == 0 log = logging.getLogger("with_file") assert len(log.handlers) >= 1
def test_setup_logging_console_only(): setup_logging.cache_clear() setup_logging("console_only", logfile=None) log = logging.getLogger("nosuch") assert len(log.handlers) == 0 log = logging.getLogger("console_only") assert len(log.handlers) >= 1
def test_logging_trace_method_verbose(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") log = setup_logging("trace_v", loglevel=TRACE, logfile=None, nocolor=True) log.trace("trace") sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\nDIAGNOSTIC Logging level for the console is set to TRACE.\nTRACE trace\n==END=="
def test_logging_trace_method_quiet(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") log = setup_logging("trace_q", logfile=None, nocolor=True) log.trace("trace") sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\n==END=="
def test_logging_debug_method_verbose(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") log = setup_logging("debug_v", loglevel=DEBUG, logfile=None, nocolor=True) log.debug("debug") sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\nDIAGNOSTIC Logging level for the console is set to DEBUG.\nDEBUG debug\n==END=="
def test_logging_error_method(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") log = setup_logging("error_method", logfile=None, nocolor=True) log.error("error") sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\nERROR error\n==END=="
def test_logging_exception_method(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") log = setup_logging("exception_method", logfile=None, nocolor=True) log.exception(GruntWurkError("exception", loglevel=CRITICAL)) sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\nCRITICAL exception\n==END=="
def test_logging_uncaught_method(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") setup_logging("uncaught_method", logfile=None, nocolor=True) log = logging.getLogger("uncaught_method") log.uncaught(GruntWurkError("uncaught")) sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\nERROR Uncaught error detected. There is no good reason why the following error wasn't handled earlier.\nERROR uncaught\n==END=="
def test_uncaught_warning(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") log = setup_logging("uncaught_warning", logfile=None, nocolor=True) e = GruntWurkConfigSettingWarning("[foo]bar", "baz", "boing, bing, bang") assert log_uncaught(log, e) == EX_OK sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\nERROR Uncaught error detected. There is no good reason why the following error wasn't handled earlier.\nWARNING The configuration setting of [foo]bar = baz is invalid. Possible values are: boing, bing, bang\n==END=="
def test_uncaught_config_error(capsys): setup_logging.cache_clear() sys.stderr.write("==START==\n") log = setup_logging("uncaught_config_error", logfile=None, nocolor=True) e = GruntWurkConfigError("An uncaught config error.") assert log_uncaught(log, e) == EX_CONFIG sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert captured.err == "==START==\nERROR Uncaught error detected. There is no good reason why the following error wasn't handled earlier.\nERROR An uncaught config error.\n==END=="
def test_config_all_defaults(): setup_logging.cache_clear() log = setup_logging("main", logfile=None, nocolor=True) config = load_config(ini="") assert config.agencyName == "Search and Rescue" assert config.logo == Path("radiolog_logo.jpg") assert config.timeoutMinutes == 30 assert len(config.tabGroups) == 0 assert config.clueReport == Path("clueReportFillable.pdf") assert config.datum == Datum.WGS84 assert config.coordFormat == CoordFormat.UTM7 assert config.firstWorkingDir == Path("testdata") assert config.secondWorkingDir == None
def test_config_bad(capsys): ini = """ [mapping] datum = XXX coordformat = XXX """ sys.stderr.write("==START==\n") setup_logging.cache_clear() log = setup_logging("main", logfile=None, nocolor=True) config = load_config(ini=ini) sys.stderr.write("==END==") captured = capsys.readouterr() assert captured.out == "" assert ( captured.err == """==START== INFO Operating system is Windows. INFO PowerShell.exe is in the path. WARNING The configuration setting of [mapping]datum = XXX is invalid. Possible values are: WGS84, NAD27 WARNING The configuration setting of [mapping]coordformat = XXX is invalid. Possible values are: UTM7, UTM5, DEG, DEGMIN, DMS, DEGLIST ==END==""" )
def test_config_all_good(): ini = """ [agency] name = International Rescue logo = thunderbirds.png [mapping] datum = NAD27 coordformat = DMS [display] timeoutminutes = 20 [tabgroups] Numbers = ^Thunderbird [A-Z]+ [reports] cluereport = fabclue.pdf [storage] firstworkingdir = C:\\ir secondworkingdir = E:\\fab """ setup_logging.cache_clear() log = setup_logging("main", logfile=None, nocolor=True) config = load_config(ini=ini) assert config.agencyName == "International Rescue" assert config.logo == Path("thunderbirds.png") assert config.timeoutMinutes == 20 assert len(config.tabGroups) == 1 assert config.tabGroups[0] == "^Thunderbird [A-Z]+" assert config.clueReport == Path("fabclue.pdf") assert config.datum == Datum.NAD27 assert config.coordFormat == CoordFormat.DMS assert config.firstWorkingDir == Path("C:\\ir") assert config.secondWorkingDir == Path("E:\\fab")