Esempio n. 1
0
def test_get_top_steps():
    first_step = step_mockup("step1", start_time=0.0, end_time=1.0)
    second_step = step_mockup("step1", start_time=1.0, end_time=3.0)
    third_step = step_mockup("step2", start_time=3.0, end_time=4.0)

    suite1 = suite_mockup("suite1").add_test(
        tst_mockup().add_step(first_step).add_step(second_step))
    suite2 = suite_mockup("suite2").add_test(tst_mockup().add_step(third_step))

    top_steps = TopSteps.get_top_steps(
        [make_suite_data_from_mockup(suite) for suite in (suite1, suite2)])

    assert len(top_steps) == 2

    assert top_steps[0][0] == "step1"
    assert top_steps[0][1] == "2"
    assert top_steps[0][2] == "1.000s"
    assert top_steps[0][3] == "2.000s"
    assert top_steps[0][4] == "1.500s"
    assert top_steps[0][5] == "3.000s"
    assert top_steps[0][6] == "75%"

    assert top_steps[1][0] == "step2"
    assert top_steps[1][1] == "1"
    assert top_steps[1][2] == "1.000s"
    assert top_steps[1][3] == "1.000s"
    assert top_steps[1][4] == "1.000s"
    assert top_steps[1][5] == "1.000s"
    assert top_steps[1][6] == "25%"
Esempio n. 2
0
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]
Esempio n. 3
0
def test_failed_to_passed():
    old_suite = suite_mockup("mysuite").add_test(tst_mockup("mytest1", status="failed"))
    new_suite = suite_mockup("mysuite").add_test(tst_mockup("mytest1", status="passed"))

    diff = compute_diff([make_suite_data_from_mockup(old_suite)], [make_suite_data_from_mockup(new_suite)])

    check_diff(diff, status_changed=[["mysuite.mytest1", "failed", "passed"]])
Esempio n. 4
0
def test_removed_test():
    old_suite = suite_mockup("mysuite").add_test(tst_mockup("mytest1")).add_test(tst_mockup("mytest2"))
    new_suite = suite_mockup("mysuite").add_test(tst_mockup("mytest1"))

    diff = compute_diff([make_suite_data_from_mockup(old_suite)], [make_suite_data_from_mockup(new_suite)])

    check_diff(diff, removed=["mysuite.mytest2"])
Esempio n. 5
0
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]
Esempio n. 6
0
def test_get_top_tests():
    suite1 = suite_mockup("suite1").add_test(
        tst_mockup("test", start_time=0.0, end_time=1.0))
    suite2 = suite_mockup("suite2").add_test(
        tst_mockup("test", start_time=1.0, end_time=4.0))

    top_suites = TopTests.get_top_tests(
        [make_suite_data_from_mockup(suite) for suite in (suite1, suite2)])
    assert len(top_suites) == 2
    assert top_suites[0][0] == "suite2.test"
    assert top_suites[0][1] == "3.000s"
    assert top_suites[0][2] == "75%"
    assert top_suites[1][0] == "suite1.test"
    assert top_suites[1][1] == "1.000s"
    assert top_suites[1][2] == "25%"
Esempio n. 7
0
def test_project_filter_on_failed():
    suite = suite_mockup("mysuite").\
        add_test(tst_mockup("test1", status="failed")).\
        add_test(tst_mockup("test2", status="passed"))

    _test_report_filter([suite], ReportFilter(statuses=["failed"]),
                        ["mysuite.test1"])
Esempio n. 8
0
def test_report_stats_simple():
    mockup = report_mockup()
    mockup.add_suite(suite_mockup().add_test(tst_mockup().add_step(
        step_mockup().add_check(True))))
    report = make_report_from_mockup(mockup)

    assert_report_stats(report,
                        expected_passed_tests=1,
                        expected_succeeded_checks=1)
Esempio n. 9
0
def test_report_stats_failure():
    mockup = report_mockup()
    mockup.add_suite(suite_mockup().add_test(
        tst_mockup(status="failed").add_step(
            step_mockup().add_check(False).add_error_log())))
    report = make_report_from_mockup(mockup)

    assert_report_stats(report,
                        expected_failed_tests=1,
                        expected_failed_checks=1,
                        expected_error_logs=1)
Esempio n. 10
0
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]
Esempio n. 11
0
def test_report_filter_on_path():
    suite = suite_mockup("mysuite").add_test(tst_mockup("mytest1")).add_test(
        tst_mockup("mytest2"))

    _test_report_filter([suite], ReportFilter(paths=["mysuite.mytest2"]),
                        ["mysuite.mytest2"])
Esempio n. 12
0
def test_suite_duration():
    suite = make_suite_data_from_mockup(suite_mockup().add_test(
        tst_mockup(start_time=NOW, end_time=NOW + 1)).add_test(
            tst_mockup(start_time=NOW + 1, end_time=NOW + 2)))
    assert suite.duration == 2
Esempio n. 13
0
def test_report_stats_skipped():
    mockup = report_mockup()
    mockup.add_suite(suite_mockup().add_test(tst_mockup(status="skipped")))
    report = make_report_from_mockup(mockup)

    assert_report_stats(report, expected_skipped_tests=1)
Esempio n. 14
0
def test_suite_duration_with_teardown():
    suite = make_suite_data_from_mockup(suite_mockup().add_test(
        tst_mockup(start_time=NOW + 1, end_time=NOW + 2)).add_teardown(
            hook_mockup(start_time=NOW + 2, end_time=NOW + 3)))
    assert suite.duration == 2