def test_testplan_decorator():
    """TODO."""
    from testplan import test_plan

    @test_plan(name='MyPlan', port=800, parse_cmdline=False)
    def main1(plan):
        plan.add(DummyTest(name='bob'))
        return 123

    res = main1()  # pylint: disable=no-value-for-parameter
    assert isinstance(res, TestplanResult)
    assert res.decorated_value == 123
    assert res.run is True

    pdf_path = 'mypdf.pdf'
    with argv_overridden('--pdf', pdf_path):
        with log_propagation_disabled(TESTPLAN_LOGGER):

            @test_plan(name='MyPlan', port=800)
            def main2(plan, parser):
                args = parser.parse_args()

                assert args.verbose is False
                assert args.pdf_path == pdf_path
                assert plan.cfg.pdf_path == pdf_path
                plan.add(DummyTest(name='bob'))

            res = main2()  # pylint:disable=assignment-from-no-return,no-value-for-parameter
            assert isinstance(res, TestplanResult)
            assert res.decorated_value is None
            assert res.run is True
def test_command_line_ordering(cmdline_args, report_ctx):

    multitest = MultiTest(name="Multitest", suites=[Beta(), Alpha()])

    with argv_overridden(*cmdline_args):
        plan = TestplanMock(name="plan", parse_cmdline=True)
        plan.add(multitest)
        plan.run()

    test_report = plan.report
    check_report_context(test_report, report_ctx)
Beispiel #3
0
def test_command_line_ordering(cmdline_args, report_ctx):

    multitest_x = MultiTest(name='Multitest', suites=[Beta(), Alpha()])

    with argv_overridden(*cmdline_args):
        plan = Testplan(name='plan', parse_cmdline=True)
        plan.add(multitest_x)

        with log_propagation_disabled(TESTPLAN_LOGGER):
            plan.run()

    test_report = plan.report
    check_report_context(test_report, report_ctx)
def test_hobbestest_listing(binary_dir, expected_output):

    binary_path = os.path.join(binary_dir, 'hobbes-test')
    cmdline_args = ['--list']

    with argv_overridden(*cmdline_args):
        plan = Testplan(name='plan', parse_cmdline=True)

        with log_propagation_disabled(TESTPLAN_LOGGER):
            with captured_logging(TESTPLAN_LOGGER) as log_capture:
                plan.add(HobbesTest(name='MyHobbesTest', driver=binary_path, tests=['Hog', 'Net', 'Recursives']))
                result = plan.run()
                print(log_capture.output)
                assert log_capture.output == expected_output
                assert len(result.test_report) == 0, 'No tests should be run.'
Beispiel #5
0
def test_command_line_filtering(cmdline_args, report_ctx):

    multitest_x = MultiTest(name="XXX", suites=[Alpha(), Beta()])
    multitest_y = MultiTest(name="YYY", suites=[Gamma()])

    with argv_overridden(*cmdline_args):
        plan = TestplanMock(name="plan", parse_cmdline=True)
        plan.add(multitest_x)
        plan.add(multitest_y)

        with log_propagation_disabled(TESTPLAN_LOGGER):
            plan.run()

    test_report = plan.report
    check_report_context(test_report, report_ctx)
Beispiel #6
0
def test_implicit_exporter_initialization(http_server):
    """
    An implicit exporting should be done if `http_url` is available
    via cmdline args but no exporters were declared programmatically.
    """
    http_url = 'http://localhost:{}'.format(http_server.server_port)

    with argv_overridden('--http', http_url):
        plan = Testplan(name='plan')
        multitest_1 = multitest.MultiTest(name='Primary', suites=[Alpha()])
        plan.add(multitest_1)
        plan.run()

    assert len(PostHandler.post_data) == 1
    PostHandler.post_data.pop()
Beispiel #7
0
def test_command_line_listing(runpath, cmdline_args, expected_output):
    multitest_x = MultiTest(name="Primary", suites=[Beta(), Alpha()])
    multitest_y = MultiTest(name="Secondary", suites=[Gamma()])

    with argv_overridden(*cmdline_args):
        plan = TestplanMock(name="plan", parse_cmdline=True, runpath=runpath)

        with captured_logging(TESTPLAN_LOGGER) as log_capture:
            plan.add(multitest_x)
            plan.add(multitest_y)

            result = plan.run()

            assert log_capture.output == expected_output
            assert len(result.test_report) == 0, "No tests should be run."
Beispiel #8
0
def test_implicit_exporter_initialization(runpath, http_server):
    """
    An implicit exporting should be done if `http_url` is available
    via cmdline args but no exporters were declared programmatically.
    """
    http_url = "http://localhost:{}".format(http_server.server_port)

    with argv_overridden("--http", http_url):
        plan = TestplanMock("plan", parse_cmdline=True, runpath=runpath)
        multitest_1 = multitest.MultiTest(name="Primary", suites=[Alpha()])
        plan.add(multitest_1)
        plan.run()

    assert len(PostHandler.post_data) == 1
    PostHandler.post_data.pop()
Beispiel #9
0
def test_implicit_exporter_initialization(tmpdir):
    """
        An implicit JSON should be generated if `json_path` is available
        via cmdline args but no exporters were declared programmatically.
    """
    json_path = tmpdir.mkdir('reports').join('report.json').strpath

    with log_propagation_disabled(TESTPLAN_LOGGER):
        with argv_overridden('--json', json_path):
            plan = Testplan(name='plan')
            multitest_1 = MultiTest(name='Primary', suites=[Alpha()])
            plan.add(multitest_1)
            plan.run()

    assert os.path.exists(json_path)
    assert os.stat(json_path).st_size > 0
Beispiel #10
0
def test_command_line_listing(cmdline_args, expected_output):
    multitest_x = MultiTest(name='Primary', suites=[Beta(), Alpha()])
    multitest_y = MultiTest(name='Secondary', suites=[Gamma()])

    with argv_overridden(*cmdline_args):
        plan = Testplan(name='plan', parse_cmdline=True)

        with log_propagation_disabled(TESTPLAN_LOGGER):
            with captured_logging(TESTPLAN_LOGGER) as log_capture:
                plan.add(multitest_x)
                plan.add(multitest_y)

                result = plan.run()

                assert log_capture.output == expected_output
                assert len(result.test_report) == 0, 'No tests should be run.'
Beispiel #11
0
def test_command_line_filtering(cmdline_args, report_ctx):

    multitest_x = MultiTest(name="XXX", suites=[Alpha(), Beta()])
    multitest_y = MultiTest(name="YYY", suites=[Gamma()])

    with argv_overridden(*cmdline_args):
        plan = TestplanMock(name="plan", parse_cmdline=True)
        plan.add(multitest_x)
        plan.add(multitest_y)
        plan.run()

    test_report = plan.report
    check_report_context(test_report, report_ctx)

    if not test_report.entries:
        assert plan.result.success
Beispiel #12
0
def test_implicit_exporter_initialization(tmpdir):
    """
        An implicit XMLExporter should be generated if `xml_dir` is available
        via cmdline args but no exporters were declared programmatically.
    """
    xml_dir = tmpdir.mkdir("xml")

    with argv_overridden("--xml", xml_dir.strpath):
        plan = Testplan(name="plan")
        multitest_1 = multitest.MultiTest(name="Primary", suites=[Alpha()])
        plan.add(multitest_1)
        plan.run()

    xml_path = xml_dir.join("primary.xml").strpath

    assert os.path.exists(xml_path)
    assert os.stat(xml_path).st_size > 0
Beispiel #13
0
def test_implicit_exporter_initialization(tmpdir):
    """
        An implicit XMLExporter should be generated if `xml_dir` is available
        via cmdline args but no exporters were declared programmatically.
    """
    xml_dir = tmpdir.mkdir('xml')

    with log_propagation_disabled(TESTPLAN_LOGGER):
        with argv_overridden('--xml', xml_dir.strpath):
            plan = Testplan(name='plan')
            multitest_1 = MultiTest(name='Primary', suites=[Alpha()])
            plan.add(multitest_1)
            plan.run()

    xml_path = xml_dir.join('primary.xml').strpath

    assert os.path.exists(xml_path)
    assert os.stat(xml_path).st_size > 0
Beispiel #14
0
def test_hobbestest_listing(binary_dir, expected_output):

    binary_path = os.path.join(binary_dir, "hobbes-test")
    cmdline_args = ["--list"]

    with argv_overridden(*cmdline_args):
        plan = TestplanMock(name="plan", parse_cmdline=True)

        with captured_logging(TESTPLAN_LOGGER) as log_capture:
            plan.add(
                HobbesTest(
                    name="My HobbesTest",
                    binary=binary_path,
                    tests=["Hog", "Net", "Recursives"],
                ))
            result = plan.run()
            print(log_capture.output)
            assert log_capture.output == expected_output
            assert len(result.test_report) == 0, "No tests should be run."
Beispiel #15
0
def test_implicit_exporter_initialization(runpath):
    """
    An implicit JSON should be generated if `json_path` is available
    via cmdline args but no exporters were declared programmatically.
    """
    json_path = os.path.join(runpath, "report.json")

    with argv_overridden("--json", json_path):
        plan = TestplanMock(name="plan", parse_cmdline=True)
        multitest_1 = multitest.MultiTest(name="Primary", suites=[Alpha()])
        plan.add(multitest_1)
        plan.run()

    assert os.path.exists(json_path)
    assert os.stat(json_path).st_size > 0

    # Load the JSON file to validate it contains valid JSON.
    with open(json_path) as json_file:
        json.load(json_file)
Beispiel #16
0
def test_implicit_exporter_initialization(tmpdir):
    """
    An implicit JSON should be generated if `json_path` is available
    via cmdline args but no exporters were declared programmatically.
    """
    json_path = tmpdir.mkdir('reports').join('report.json').strpath

    with argv_overridden('--json', json_path):
        plan = Testplan(name='plan')
        multitest_1 = multitest.MultiTest(name='Primary', suites=[Alpha()])
        plan.add(multitest_1)
        plan.run()

    assert os.path.exists(json_path)
    assert os.stat(json_path).st_size > 0

    # Load the JSON file to validate it contains valid JSON.
    with open(json_path) as json_file:
        json.load(json_file)
Beispiel #17
0
def test_implicit_exporter_initialization(tmpdir):
    """
        An implicit PDFExporter should be generated if `pdf_path` is available
        via cmdline args but no exporters were declared.

        Multiple implicit TagFilteredPDFExporters should be initialized
        if `report_tags` or `report_tags_all` arguments are passed
        via cmdline, but no exporters were declared.
    """
    pdf_dir = tmpdir.mkdir("reports")
    pdf_path = pdf_dir.join("my_report.pdf").strpath

    @testsuite
    class MySuite(object):
        @testcase
        def test_comparison(self, env, result):
            result.equal(1, 1, "equality description")

        @testcase(tags="foo")
        def test_membership(self, env, result):
            result.contain(1, [1, 2, 3])

    with log_propagation_disabled(TESTPLAN_LOGGER):
        with argv_overridden(
                "--pdf",
                pdf_path,
                "--report-tags",
                "foo",
                "--report-dir",
                pdf_dir.strpath,
        ):
            multitest = MultiTest(name="MyMultitest", suites=[MySuite()])

            plan = TestplanMock(name="plan", parse_cmdline=True)
            plan.add(multitest)
            plan.run()

    tag_pdf_path = pdf_dir.join("report-tags-any-foo.pdf").strpath
    assert os.path.exists(pdf_path)
    assert os.path.exists(tag_pdf_path)
    assert os.stat(pdf_path).st_size > 0
    assert os.stat(tag_pdf_path).st_size > 0