def test_diff_cmd(tmpdir, cmdout): old_report = report_mockup() old_report.add_suite( suite_mockup("mysuite"). add_test(tst_mockup("mytest1", status="passed")). add_test(tst_mockup("mytest2", status="failed")). add_test(tst_mockup("mytest3")) ) new_report = report_mockup() new_report.add_suite( suite_mockup("mysuite"). add_test(tst_mockup("mytest1", status="failed")). add_test(tst_mockup("mytest2", status="passed")). add_test(tst_mockup("mytest4")) ) old_report_path = tmpdir.join("old_report.json").strpath save_report_into_file(make_report_from_mockup(old_report), old_report_path) new_report_path = tmpdir.join("new_report.json").strpath save_report_into_file(make_report_from_mockup(new_report), new_report_path) assert main(["diff", old_report_path, new_report_path]) == 0 lines = cmdout.get_lines() splitted = _split_lines(lines, "") added = next(splitted) removed = next(splitted) status_changed = next(splitted) assert "mysuite.mytest4" in added[1] assert "mysuite.mytest3" in removed[1] assert "mysuite.mytest2" in status_changed[1] assert "mysuite.mytest1" in status_changed[2]
def test_report_test_run_in_progress(report_in_progress_path, cmdout): assert main(["report", report_in_progress_path]) == 0 cmdout.dump() cmdout.assert_substrs_anywhere(["suite.test_1"]) cmdout.assert_substrs_anywhere(["step"]) cmdout.assert_substrs_anywhere(["message"])
def test_report_detailed_with_filter(tmpdir, cmdout): run_suite_class(mysuite, tmpdir=tmpdir, backends=[JsonBackend()]) assert main(["report", tmpdir.strpath, "--failed"]) == 0 cmdout.dump() cmdout.assert_substrs_in_line(0, ["My Test 1"]) cmdout.assert_substrs_in_line(1, ["mysuite.mytest1"]) cmdout.assert_substrs_in_line(3, ["My Test 1"]) cmdout.assert_substrs_in_line(5, ["ERROR", "failure"]) cmdout.assert_lines_nb(9)
def test_top_steps_cmd(tmpdir, cmdout): report = report_mockup().add_suite( suite_mockup("suite1").add_test(tst_mockup().add_step( step_mockup("step1", start_time=0.1, end_time=1.0)))) report_path = tmpdir.join("report.json").strpath save_report_into_file(make_report_from_mockup(report), report_path) assert main(["top-steps", report_path]) == 0 lines = cmdout.get_lines() assert "step1" in lines[4]
def test_top_tests_cmd(tmpdir, cmdout): suite1 = suite_mockup("suite1").add_test( tst_mockup("test", start_time=0.1, end_time=1.0)) suite2 = suite_mockup("suite2").add_test( tst_mockup("test", start_time=1.0, end_time=4.0)) report = report_mockup().add_suite(suite1).add_suite(suite2) report_path = tmpdir.join("report.json").strpath save_report_into_file(make_report_from_mockup(report), report_path) assert main(["top-tests", report_path]) == 0 lines = cmdout.get_lines() assert "suite2.test" in lines[4]
def test_report_detailed_with_arguments(tmpdir, cmdout): run_suite_class(mysuite, tmpdir=tmpdir, backends=[JsonBackend()]) assert main(["report", tmpdir.strpath, "--explicit", "--max-width=80"]) == 0 cmdout.dump() cmdout.assert_substrs_in_line(0, ["FAILED: My Test 1"]) cmdout.assert_substrs_in_line(1, ["mysuite.mytest1"]) cmdout.assert_substrs_in_line(3, ["My Test 1"]) cmdout.assert_substrs_in_line(5, ["ERROR", "failure"]) cmdout.assert_substrs_in_line(8, ["My Test 2"]) cmdout.assert_substrs_in_line(9, ["mysuite.mytest2"]) cmdout.assert_substrs_in_line(10, ["n/a"]) cmdout.assert_lines_nb(13)
def run_main(args): return main(args)
def test_top_tests_cmd_test_run_in_progress(report_in_progress_path, cmdout): assert main(["top-tests", report_in_progress_path]) == 0 cmdout.dump() cmdout.assert_substrs_anywhere(["suite.test_2"])
def test_top_steps_cmd_test_run_in_progress(report_in_progress_path, cmdout): assert main(["top-steps", report_in_progress_path]) == 0 cmdout.dump() cmdout.assert_substrs_anywhere(["step"])
def test_report_with_filter(tmpdir, cmdout): run_suite_class(mysuite, tmpdir=tmpdir, backends=[JsonBackend()]) assert main(["report", tmpdir.strpath, "--passed", "--short"]) == 0 assert_run_output(cmdout, "mysuite", successful_tests=["mytest2"])
def test_report_from_file(tmpdir, cmdout): backend = JsonBackend() run_suite_class(mysuite, tmpdir=tmpdir, backends=[backend]) assert main(["report", osp.join(tmpdir.strpath, backend.get_report_filename()), "--short"]) == 0 assert_run_output(cmdout, "mysuite", successful_tests=["mytest2"], failed_tests=["mytest1"])
def test_report_from_dir(tmpdir, cmdout): run_suite_class(mysuite, tmpdir=tmpdir, backends=[JsonBackend()]) assert main(["report", tmpdir.strpath, "--short"]) == 0 assert_run_output(cmdout, "mysuite", successful_tests=["mytest2"], failed_tests=["mytest1"])
#!/usr/bin/env python import sys import os sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from lemoncheesecake.cli import main sys.exit(main())
def test_diff_cmd_test_run_in_progress(report_in_progress_path, cmdout): assert main(["diff", report_in_progress_path, report_in_progress_path]) == 0 cmdout.assert_substrs_anywhere("no difference")