def test_shows_help(capsys): test_args = ["valid8"] with patch.object(sys, "argv", test_args): try: cli.main() except SystemExit: pass out, err = capsys.readouterr() assert out.startswith("usage") or err.startswith("usage")
def test_lint_ok_from_content(file_from_content, capsys): test_args = ["test", "lint", file_from_content.as_posix()] with patch.object(sys, "argv", test_args): try: cli.main() except SystemExit: pytest.fail("SystemExit was raised when linting a correct file") out, err = capsys.readouterr() assert "good" in out
def test_lint_fails_from_content(file_from_content, capsys): test_args = ["test", "lint", file_from_content.as_posix()] with patch.object(sys, "argv", test_args): with pytest.raises(SystemExit) as sysexit: cli.main() exit_code = sysexit.value.code assert exit_code == 2 out, err = capsys.readouterr() assert len(out) != 0
def test_lint_ok(path, capsys): test_args = ["test", "lint", path] with patch.object(sys, "argv", test_args): try: cli.main() except SystemExit: pytest.fail("SystemExit was raised when linting a correct file") out, err = capsys.readouterr() assert "good" in out
def compare_main_with_expected_output(test_args, expected, capsys): with patch.object(sys, "argv", test_args): try: cli.main() except SystemExit as sysexit: out, err = capsys.readouterr() if expected is True: assert sysexit.code == 0 assert out.strip().endswith("True") else: assert sysexit != 0 assert out.strip().endswith("False")