def test_logging( decider_mock, tmp_path, verbosity_flags, exp_logging_level, coloredlogs_module, capsys, ): """Ensure logging configuration is set up correctly.""" # Setup environment coloredlogs_patch = mock.patch.dict(sys.modules, {"coloredlogs": coloredlogs_module}) root_logger = lg.RootLogger("WARNING") root_logger_patch = mock.patch.object(lg, "root", root_logger) # Run function parser = seddy_main.build_parser() args = parser.parse_args( verbosity_flags + ["decider", str(tmp_path / "workflows.json"), "spam", "eggs"]) with root_logger_patch, coloredlogs_patch: seddy_main.run_app(args) # Check logging configuration assert root_logger.level == exp_logging_level root_logger.critical("spam") assert capsys.readouterr().err[24:] == "[CRITICAL] root: spam\n"
def test_version(decider_mock, command_line_args, capsys): """Ensure version is displayed.""" # Run function parser = seddy_main.build_parser() with pytest.raises(SystemExit) as e: parser.parse_args(command_line_args) assert e.value.code == 0 # Check output res_out = capsys.readouterr().out assert res_out.strip() == pkg_resources.get_distribution("seddy").version
def test_decider(decider_mock, tmp_path, args_extra, decider_args): """Ensure decider application is run with the correct input.""" # Run function parser = seddy_main.build_parser() args = parser.parse_args( ["decider", str(tmp_path / "workflows.json"), "spam", "eggs"] + args_extra) seddy_main.run_app(args) # Check application input decider_mock.assert_called_once_with(tmp_path / "workflows.json", "spam", "eggs", *decider_args)
def test_usage(decider_mock, command_line_args, capsys, description): """Ensure usage is displayed.""" # Run function parser = seddy_main.build_parser() with pytest.raises(SystemExit) as e: parser.parse_args(command_line_args) assert e.value.code == 0 # Check output res_out = capsys.readouterr().out assert res_out[:6] == "usage:" assert res_out.splitlines()[2] == description
def test_register(tmp_path): """Ensure workflow registration application is run correctly.""" # Setup environment run_app_mock = mock.Mock() run_app_patch = mock.patch.object(seddy_registration, "run_app", run_app_mock) # Run function parser = seddy_main.build_parser() args = parser.parse_args( ["register", str(tmp_path / "workflows.json"), "spam"]) with run_app_patch: seddy_main.run_app(args) # Check application input run_app_mock.assert_called_once_with(tmp_path / "workflows.json", "spam")
def test_json_logging(decider_mock, tmp_path, coloredlogs_module, capsys): """Ensure JSON logging configuration is set up correctly.""" # Setup environment root_logger = lg.RootLogger("WARNING") root_logger_patch = mock.patch.object(lg, "root", root_logger) # Run function parser = seddy_main.build_parser() args = parser.parse_args( ["-J", "decider", str(tmp_path / "workflows.json"), "spam", "eggs"]) with root_logger_patch: seddy_main.run_app(args) # Check logging configuration root_logger.warning("spam %s", "eggs") assert json.loads(capsys.readouterr().err) == { "levelname": "WARNING", "name": "root", "timestamp": mock.ANY, "message": "spam eggs", }