示例#1
0
 def test_handles_python_exeception(self):
     test_case = self.create_test("test", True)
     test_list = TestList()
     test_list.add_test(test_case)
     test_case.run.side_effect = KeyError
     self.runner.run(test_list)
     self.assertTrue(self.report.result_of("test").failed)
示例#2
0
    def create_tests(self, simulator_if, elaborate_only, test_list=None):
        """
        Create all test cases from this test bench
        """

        self._check_architectures(self.design_unit)

        if test_list is None:
            test_list = TestList()

        if self._individual_tests:
            for test_case in self._test_cases:
                test_case.create_tests(simulator_if, elaborate_only, test_list)
        elif self._implicit_test:
            for config in self._get_configurations_to_run():
                test_list.add_test(
                    IndependentSimTestCase(
                        test=self._implicit_test,
                        config=config,
                        simulator_if=simulator_if,
                        elaborate_only=elaborate_only))
        else:
            for config in self._get_configurations_to_run():
                test_list.add_suite(
                    SameSimTestSuite(
                        tests=[test.test for test in self._test_cases],
                        config=config,
                        simulator_if=simulator_if,
                        elaborate_only=elaborate_only))
        return test_list
示例#3
0
    def test_can_read_output(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir)

        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)

        def side_effect(read_output, **kwargs):  # pylint: disable=unused-argument
            """
            Side effect that print output to stdout
            """
            print("out1", end="")
            print("out2", end="")
            assert read_output() == "out1out2"
            print("out3", end="")
            print("out4", end="")
            assert read_output() == "out1out2out3out4"
            print("out5", end="")
            return True

        test_case.run_side_effect = side_effect
        runner.run(test_list)
        self.assertTrue(report.result_of("test").passed)
        self.assertEqual(report.result_of("test").output, "out1out2out3out4out5")
示例#4
0
 def test_handles_python_exeception(self):
     test_case = self.create_test("test", True)
     test_list = TestList()
     test_list.add_test(test_case)
     test_case.run.side_effect = KeyError
     self.runner.run(test_list)
     self.assertTrue(self.report.result_of("test").failed)
示例#5
0
    def test_can_read_output(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir)

        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)

        def side_effect(read_output, **kwargs):  # pylint: disable=unused-argument
            """
            Side effect that print output to stdout
            """
            print("out1", end="")
            print("out2", end="")
            assert read_output() == "out1out2"
            print("out3", end="")
            print("out4", end="")
            assert read_output() == "out1out2out3out4"
            print("out5", end="")
            return True

        test_case.run_side_effect = side_effect
        runner.run(test_list)
        self.assertTrue(report.result_of("test").passed)
        self.assertEqual(report.result_of("test").output, "out1out2out3out4out5")
示例#6
0
    def test_handles_python_exeception(self):
        report = TestReport()
        runner = TestRunner(report, self.output_path)

        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)
        test_case.run.side_effect = KeyError
        runner.run(test_list)
        self.assertTrue(report.result_of("test").failed)
示例#7
0
 def test_runs_testcases_in_order(self):
     test_case1 = self.create_test("test1", True)
     test_case2 = self.create_test("test2", False)
     test_list = TestList()
     test_list.add_test(test_case1)
     test_list.add_test(test_case2)
     self.runner.run(test_list)
     test_case1.run.assert_called_once_with(create_output_path(self.output_path, "test1"))
     test_case2.run.assert_called_once_with(create_output_path(self.output_path, "test2"))
     self.assertEqual(self._tests, ["test1", "test2"])
     self.assertTrue(self.report.result_of("test1").passed)
     self.assertTrue(self.report.result_of("test2").failed)
示例#8
0
 def test_runs_testcases_in_order(self):
     test_case1 = self.create_test("test1", True)
     test_case2 = self.create_test("test2", False)
     test_list = TestList()
     test_list.add_test(test_case1)
     test_list.add_test(test_case2)
     self.runner.run(test_list)
     test_case1.run.assert_called_once_with(join(self.output_path, "test1"))
     test_case2.run.assert_called_once_with(join(self.output_path, "test2"))
     self.assertEqual(self._tests, ["test1", "test2"])
     self.assertTrue(self.report.result_of("test1").passed)
     self.assertTrue(self.report.result_of("test2").failed)
示例#9
0
    def test_handles_python_exeception(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir)

        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)

        def side_effect(*args, **kwargs):  # pylint: disable=unused-argument
            raise KeyError

        test_case.run_side_effect = side_effect
        runner.run(test_list)
        self.assertTrue(report.result_of("test").failed)
示例#10
0
    def test_handles_python_exeception(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir)

        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)

        def side_effect(*args, **kwargs):  # pylint: disable=unused-argument
            raise KeyError

        test_case.run_side_effect = side_effect
        runner.run(test_list)
        self.assertTrue(report.result_of("test").failed)
示例#11
0
    def test_collects_output(self):
        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)

        output = "Output string, <xml>, </xml>\n"

        def side_effect(*args, **kwargs):
            print(output, end="")
            return True

        test_case.run.side_effect = side_effect
        self.runner.run(test_list)
        self.assertTrue(self.report.result_of("test").passed)
        self.assertEqual(self.report.result_of("test").output, output)
示例#12
0
 def from_project(self, project, entity_filter=None):
     test_list = TestList()
     for library in project.get_libraries():
         for entity in library.get_entities():
             if entity_filter is None or entity_filter(entity):
                 self._create_tests_from_entity(test_list, entity)
     return test_list
示例#13
0
 def create_tests(self, simulator_if, elaborate_only):
     """
     Create all test cases from the test benches
     """
     test_list = TestList()
     for test_bench in self.get_test_benches():
         test_bench.create_tests(simulator_if, elaborate_only, test_list)
     return test_list
示例#14
0
    def test_collects_output(self):
        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)

        output = "Output string, <xml>, </xml>\n"

        def side_effect(*args, **kwargs):  # pylint: disable=unused-argument
            """
            Side effect that print output to stdout
            """
            print(output, end="")
            return True

        test_case.run.side_effect = side_effect
        self.runner.run(test_list)
        self.assertTrue(self.report.result_of("test").passed)
        self.assertEqual(self.report.result_of("test").output, output)
示例#15
0
    def test_runs_testcases_in_order(self):
        report = TestReport()
        runner = TestRunner(report, self.output_path)

        test_case1 = self.create_test("test1", True)
        test_case2 = self.create_test("test2", False)
        test_case3 = self.create_test("test3", True)
        test_list = TestList()
        test_list.add_test(test_case1)
        test_list.add_test(test_case2)
        runner.run(test_list)
        test_case1.run.assert_called_once_with(
            create_output_path(self.output_path, "test1"))
        test_case2.run.assert_called_once_with(
            create_output_path(self.output_path, "test2"))
        self.assertFalse(test_case3.run.called)
        self.assertEqual(self._tests, ["test1", "test2"])
        self.assertTrue(report.result_of("test1").passed)
        self.assertTrue(report.result_of("test2").failed)
示例#16
0
    def test_fail_fast(self):
        report = TestReport()
        runner = TestRunner(report, self.output_path, fail_fast=True)

        test_case1 = self.create_test("test1", True)
        test_case2 = self.create_test("test2", False)
        test_list = TestList()
        test_list.add_test(test_case1)
        test_list.add_test(test_case2)
        try:
            runner.run(test_list)
        except KeyboardInterrupt:
            pass
        test_case1.run.assert_called_once_with(
            create_output_path(self.output_path, "test1"))
        test_case2.run.assert_called_once_with(
            create_output_path(self.output_path, "test2"))
        self.assertEqual(self._tests, ["test1", "test2"])
        self.assertTrue(report.result_of("test1").passed)
        self.assertTrue(report.result_of("test2").failed)
示例#17
0
    def test_runs_testcases_in_order(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir)

        order = []
        test_case1 = self.create_test("test1", True, order=order)
        test_case2 = self.create_test("test2", False, order=order)
        test_case3 = self.create_test("test3", True, order=order)
        test_list = TestList()
        test_list.add_test(test_case1)
        test_list.add_test(test_case2)
        test_list.add_test(test_case3)
        runner.run(test_list)
        self.assertEqual(test_case1.output_path, create_output_path(tempdir, "test1"))
        self.assertEqual(test_case2.output_path, create_output_path(tempdir, "test2"))
        self.assertEqual(test_case3.output_path, create_output_path(tempdir, "test3"))
        self.assertEqual(order, ["test1", "test2", "test3"])
        self.assertTrue(report.result_of("test1").passed)
        self.assertTrue(report.result_of("test2").failed)
        self.assertTrue(report.result_of("test3").passed)
示例#18
0
    def test_collects_output(self):
        report = TestReport()
        runner = TestRunner(report, self.output_path)

        test_case = self.create_test("test", True)
        test_list = TestList()
        test_list.add_test(test_case)

        output = "Output string, <xml>, </xml>\n"

        def side_effect(*args, **kwargs):  # pylint: disable=unused-argument
            """
            Side effect that print output to stdout
            """
            print(output, end="")
            return True

        test_case.run.side_effect = side_effect
        runner.run(test_list)
        self.assertTrue(report.result_of("test").passed)
        self.assertEqual(report.result_of("test").output, output)
示例#19
0
    def create_tests(self, simulator_if, elaborate_only, test_list=None):
        """
        Create all test cases from this test bench
        """

        self._check_architectures(self.design_unit)

        if test_list is None:
            test_list = TestList()

        if self._individual_tests:
            for test_case in self._test_cases:
                test_case.create_tests(simulator_if, elaborate_only, test_list)
        elif self._implicit_test:
            for config in self._get_configurations_to_run():
                test_list.add_test(
                    IndependentSimTestCase(test=self._implicit_test,
                                           config=config,
                                           simulator_if=simulator_if,
                                           elaborate_only=elaborate_only))
        else:
            for config in self._get_configurations_to_run():
                test_list.add_suite(
                    SameSimTestSuite(
                        tests=[test.test for test in self._test_cases],
                        config=config,
                        simulator_if=simulator_if,
                        elaborate_only=elaborate_only))
        return test_list
示例#20
0
    def test_fail_fast(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir, fail_fast=True)

        order = []
        test_case1 = self.create_test("test1", True, order=order)
        test_case2 = self.create_test("test2", False, order=order)
        test_case3 = self.create_test("test3", True, order=order)
        test_list = TestList()
        test_list.add_test(test_case1)
        test_list.add_test(test_case2)
        test_list.add_test(test_case3)
        try:
            runner.run(test_list)
        except KeyboardInterrupt:
            pass
        self.assertEqual(test_case1.output_path, create_output_path(tempdir, "test1"))
        self.assertEqual(test_case2.output_path, create_output_path(tempdir, "test2"))
        self.assertEqual(test_case3.called, False)
        self.assertEqual(order, ["test1", "test2"])
        self.assertTrue(report.result_of("test1").passed)
        self.assertTrue(report.result_of("test2").failed)
示例#21
0
    def from_project(self, project, entity_filter=None):
        """
        Return a TestList with all test found within the project
        entity_filter -- An optional filter function of entity objects
        """
        test_list = TestList()
        for library in sorted(project.get_libraries(), key=lambda lib: lib.name):
            for entity in sorted(library.get_entities(), key=lambda ent: ent.name):
                if entity_filter is None or entity_filter(entity):
                    self._create_tests_from_entity(test_list, entity)

            for module in sorted(library.get_modules(), key=lambda module: module.name):
                if entity_filter is None or entity_filter(module):
                    self._create_tests_from_module(test_list, module)
        return test_list
示例#22
0
    def test_runs_testcases_in_order(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir)

        order = []
        test_case1 = self.create_test("test1", True, order=order)
        test_case2 = self.create_test("test2", False, order=order)
        test_case3 = self.create_test("test3", True, order=order)
        test_list = TestList()
        test_list.add_test(test_case1)
        test_list.add_test(test_case2)
        test_list.add_test(test_case3)
        runner.run(test_list)
        self.assertEqual(test_case1.output_path, create_output_path(tempdir, "test1"))
        self.assertEqual(test_case2.output_path, create_output_path(tempdir, "test2"))
        self.assertEqual(test_case3.output_path, create_output_path(tempdir, "test3"))
        self.assertEqual(order, ["test1", "test2", "test3"])
        self.assertTrue(report.result_of("test1").passed)
        self.assertTrue(report.result_of("test2").failed)
        self.assertTrue(report.result_of("test3").passed)
示例#23
0
    def test_fail_fast(self, tempdir):
        report = TestReport()
        runner = TestRunner(report, tempdir, fail_fast=True)

        order = []
        test_case1 = self.create_test("test1", True, order=order)
        test_case2 = self.create_test("test2", False, order=order)
        test_case3 = self.create_test("test3", True, order=order)
        test_list = TestList()
        test_list.add_test(test_case1)
        test_list.add_test(test_case2)
        test_list.add_test(test_case3)
        try:
            runner.run(test_list)
        except KeyboardInterrupt:
            pass
        self.assertEqual(test_case1.output_path, create_output_path(tempdir, "test1"))
        self.assertEqual(test_case2.output_path, create_output_path(tempdir, "test2"))
        self.assertEqual(test_case3.called, False)
        self.assertEqual(order, ["test1", "test2"])
        self.assertTrue(report.result_of("test1").passed)
        self.assertTrue(report.result_of("test2").failed)