Ejemplo n.º 1
0
    def test_create_output_path_on_windows(self):
        with mock.patch("sys.platform", new="win32"):
            with mock.patch("os.environ", new={}):
                output_path = "output_path"
                test_name = "_" * 400
                test_output = create_output_path(output_path, test_name)
                self.assertEqual(len(test_output), 260 - 100 + 1)

            with mock.patch("os.environ",
                            new={"VUNIT_TEST_OUTPUT_PATH_MARGIN": "-1000"}):
                output_path = "output_path"
                test_name = "_" * 400
                test_output = create_output_path(output_path, test_name)
                self.assertEqual(
                    test_output,
                    join(abspath(output_path),
                         test_name + "_" + hash_string(test_name)),
                )

            with mock.patch("os.environ",
                            new={"VUNIT_SHORT_TEST_OUTPUT_PATHS": ""}):
                output_path = "output_path"
                test_name = "_" * 400
                test_output = create_output_path(output_path, test_name)
                self.assertEqual(
                    test_output,
                    join(abspath(output_path), hash_string(test_name)))
Ejemplo n.º 2
0
    def test_create_output_path_on_linux(self):
        with mock.patch("sys.platform", new="linux"):
            with mock.patch("os.environ", new={}):
                output_path = "output_path"
                test_name = "_" * 400
                test_output = create_output_path(output_path, test_name)
                self.assertEqual(
                    test_output,
                    join(abspath(output_path),
                         test_name + "_" + hash_string(test_name)),
                )

                output_path = "output_path"
                test_name = "123._-+"
                test_output = create_output_path(output_path, test_name)
                self.assertEqual(
                    test_output,
                    join(abspath(output_path),
                         test_name + "_" + hash_string(test_name)),
                )

                output_path = "output_path"
                test_name = "#<>:"
                safe_name = "____"
                test_output = create_output_path(output_path, test_name)
                self.assertEqual(
                    test_output,
                    join(abspath(output_path),
                         safe_name + "_" + hash_string(test_name)),
                )
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)