From 7f6e8614c60842cfe0be9ffa897311bd7d5e224d Mon Sep 17 00:00:00 2001 From: jce Date: Fri, 12 Jan 2024 18:19:46 +0100 Subject: [PATCH] Import xunit2rst as dut --- tests/acceptance_test.py | 6 +-- tests/mako_test.py | 6 +-- tests/prefix_test.py | 88 ++++++++++++++++++++-------------------- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/tests/acceptance_test.py b/tests/acceptance_test.py index d598afc..b70df25 100644 --- a/tests/acceptance_test.py +++ b/tests/acceptance_test.py @@ -8,7 +8,7 @@ import unittest from pathlib import Path -from mlx.xunit2rst import create_parser, generate_xunit_to_rst +from mlx.xunit2rst import xunit2rst as dut TOP_DIR = Path(__file__).parents[1] TEST_OUT_DIR = Path(__file__).parent / 'test_out' @@ -18,7 +18,7 @@ def xunit2rst_check(input_xml, output_rst, itemize_suites=False, prefix='', trim=False, type_=None, failures=False, log_file='', add_links=False): ''' Helper function for testing whether mlx.xunit2rst produces the expected output ''' - arg_parser = create_parser() + arg_parser = dut.create_parser() command = ['-i', input_xml, '-o', output_rst] if itemize_suites: command.append('--itemize-suites') @@ -37,7 +37,7 @@ def xunit2rst_check(input_xml, output_rst, itemize_suites=False, prefix='', trim print(command) args = arg_parser.parse_args(command) - generate_xunit_to_rst( + dut.generate_xunit_to_rst( args.input_file, args.rst_output_file, args.itemize_suites, diff --git a/tests/mako_test.py b/tests/mako_test.py index db92083..127e034 100644 --- a/tests/mako_test.py +++ b/tests/mako_test.py @@ -4,7 +4,7 @@ from pathlib import Path from unittest import TestCase -from mlx.xunit2rst import ITEST, render_template +from mlx.xunit2rst import xunit2rst as dut TEST_OUT_DIR = Path(__file__).parent / 'test_out' @@ -16,13 +16,13 @@ def test_mako_error_handling(self): variable ''' kwargs = { 'report_name': 'my_report', - 'info': ITEST, + 'info': dut.ITEST, 'prefix': 'MAKO_TEST-', } test_case = TestCase() with test_case.assertLogs() as log_cm: with self.assertRaises(TypeError): - render_template((TEST_OUT_DIR / 'never_created_file.rst'), **kwargs) + dut.render_template((TEST_OUT_DIR / 'never_created_file.rst'), **kwargs) test_case.assertIn('Exception raised in Mako template, which will be re-raised after logging line info:', log_cm.output[0]) test_case.assertIn('File ', log_cm.output[-1]) diff --git a/tests/prefix_test.py b/tests/prefix_test.py index cd61534..7753ca4 100644 --- a/tests/prefix_test.py +++ b/tests/prefix_test.py @@ -3,7 +3,7 @@ import unittest from pathlib import Path -from mlx.xunit2rst import build_prefix_and_set, parse_xunit_root, verify_prefix_set, ITEST, UTEST, QTEST +from mlx.xunit2rst import xunit2rst as dut TEST_IN_DIR = Path(__file__).parent / 'test_in' @@ -11,37 +11,37 @@ class TestPrefix(unittest.TestCase): def test_build_prefix_and_set_utest_default(self): ''' Use default prefix for unit test reports ''' - test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_no_prefix_report.xml') - self.assertEqual(initial_prefix_set, UTEST) + test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_no_prefix_report.xml') + self.assertEqual(initial_prefix_set, dut.UTEST) - prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, '', True, None) + prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, '', True, None) self.assertEqual(prefix_set, initial_prefix_set) self.assertEqual(prefix, 'UTEST-') def test_build_prefix_and_set_itest_default(self): ''' Use default prefix for integration test reports ''' - test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'itest_report.xml') - self.assertEqual(initial_prefix_set, ITEST) + test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'itest_report.xml') + self.assertEqual(initial_prefix_set, dut.ITEST) - prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, '', True, None) + prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, '', True, None) self.assertEqual(prefix_set, initial_prefix_set) self.assertEqual(prefix, 'ITEST-') def test_build_prefix_and_set_from_name(self): ''' Get prefix from element name ''' - test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml') - self.assertEqual(initial_prefix_set, UTEST) + test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml') + self.assertEqual(initial_prefix_set, dut.UTEST) - prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, '', True, None) + prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, '', True, None) self.assertEqual(prefix_set, initial_prefix_set) self.assertEqual(prefix, 'UTEST_MY_LIB-') def test_build_prefix_and_set_from_arg(self): ''' Get prefix from input argument `--prefix` and trim suffix of prefix ''' - test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml') - self.assertEqual(initial_prefix_set, UTEST) + test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml') + self.assertEqual(initial_prefix_set, dut.UTEST) - prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, 'TEST_MY_LIB_-', True, None) + prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, 'TEST_MY_LIB_-', True, None) self.assertEqual(prefix_set, initial_prefix_set) self.assertEqual(prefix, 'TEST_MY_LIB-') @@ -50,32 +50,32 @@ def test_build_prefix_and_set_from_arg_swap_set(self): Get prefix from input argument `--prefix` and base prefix_set on its first letter. Don't trim suffix of prefix. ''' - test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'itest_report.xml') - self.assertEqual(initial_prefix_set, ITEST) + test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'itest_report.xml') + self.assertEqual(initial_prefix_set, dut.ITEST) - prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_MY_LIB_-', False, None) + prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_MY_LIB_-', False, None) self.assertNotEqual(prefix_set, initial_prefix_set) - self.assertEqual(prefix_set, UTEST) + self.assertEqual(prefix_set, dut.UTEST) self.assertEqual(prefix, 'UTEST_MY_LIB_-') def test_build_prefix_and_set_priority(self): ''' Argument --type must have the highest priority for determining the correct prefix_set. ''' - test_suites, initial_prefix_set, _ = parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml') - self.assertEqual(initial_prefix_set, UTEST) + test_suites, initial_prefix_set, _ = dut.parse_xunit_root(TEST_IN_DIR / 'utest_my_lib_report.xml') + self.assertEqual(initial_prefix_set, dut.UTEST) - prefix_set, prefix = build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_HOWDY-', False, 'i') + prefix_set, prefix = dut.build_prefix_and_set(test_suites, initial_prefix_set, 'UTEST_HOWDY-', False, 'i') self.assertNotEqual(prefix_set, initial_prefix_set) - self.assertEqual(prefix_set, ITEST) + self.assertEqual(prefix_set, dut.ITEST) self.assertEqual(prefix, 'UTEST_HOWDY-') def test_content_files(self): ''' Test the extraction of the content file path ''' - _, _, content_files = parse_xunit_root(TEST_IN_DIR / 'qtest_my_lib_report.xml') + _, _, content_files = dut.parse_xunit_root(TEST_IN_DIR / 'qtest_my_lib_report.xml') self.assertEqual(content_files, {3: Path("../../doc/source/extra_content.yml")}) def test_content_files_no_root(self): ''' Test the extraction of the content file path when the XML has no valid root element ''' - _, _, content_files = parse_xunit_root(TEST_IN_DIR / 'itest_report.xml') + _, _, content_files = dut.parse_xunit_root(TEST_IN_DIR / 'itest_report.xml') self.assertEqual(content_files, {0: Path('./extra_content1.yml')}) def test_verify_prefix_set(self): @@ -84,31 +84,31 @@ def test_verify_prefix_set(self): start with u/i/q (case-insensitive). The prefix argument has the second highest priority. A last resort is to keep the input prefix_set. ''' - self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'Itest'), ITEST) - self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'i'), ITEST) - self.assertEqual(verify_prefix_set(UTEST, '', 'i'), ITEST) - self.assertEqual(verify_prefix_set(ITEST, 'ITEST-', 'Utest'), UTEST) - self.assertEqual(verify_prefix_set(UTEST, 'ITEST-', 'u'), UTEST) - self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'u'), UTEST) - self.assertEqual(verify_prefix_set(UTEST, 'BLAH-', None), UTEST) - self.assertEqual(verify_prefix_set(ITEST, 'BLAH-', None), ITEST) - self.assertEqual(verify_prefix_set(UTEST, 'ITEST-', None), ITEST) - self.assertEqual(verify_prefix_set(ITEST, 'UTEST-', None), UTEST) - self.assertEqual(verify_prefix_set(ITEST, 'QTEST-', None), QTEST) - self.assertEqual(verify_prefix_set(ITEST, 'ITEST-', 'q'), QTEST) - self.assertEqual(verify_prefix_set(UTEST, 'UTEST-', 'Qtest'), QTEST) - self.assertEqual(verify_prefix_set(QTEST, '', 'u'), UTEST) - self.assertEqual(verify_prefix_set(QTEST, '', 'i'), ITEST) - self.assertEqual(verify_prefix_set(QTEST, 'UTEST', 'i'), ITEST) - self.assertEqual(verify_prefix_set(QTEST, 'FOO-', None), QTEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'Itest'), dut.ITEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'i'), dut.ITEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, '', 'i'), dut.ITEST) + self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'ITEST-', 'Utest'), dut.UTEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'ITEST-', 'u'), dut.UTEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'u'), dut.UTEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'BLAH-', None), dut.UTEST) + self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'BLAH-', None), dut.ITEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'ITEST-', None), dut.ITEST) + self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'UTEST-', None), dut.UTEST) + self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'QTEST-', None), dut.QTEST) + self.assertEqual(dut.verify_prefix_set(dut.ITEST, 'ITEST-', 'q'), dut.QTEST) + self.assertEqual(dut.verify_prefix_set(dut.UTEST, 'UTEST-', 'Qtest'), dut.QTEST) + self.assertEqual(dut.verify_prefix_set(dut.QTEST, '', 'u'), dut.UTEST) + self.assertEqual(dut.verify_prefix_set(dut.QTEST, '', 'i'), dut.ITEST) + self.assertEqual(dut.verify_prefix_set(dut.QTEST, 'UTEST', 'i'), dut.ITEST) + self.assertEqual(dut.verify_prefix_set(dut.QTEST, 'FOO-', None), dut.QTEST) with self.assertRaises(ValueError): - verify_prefix_set(UTEST, 'UTEST-', 't') + dut.verify_prefix_set(dut.UTEST, 'UTEST-', 't') with self.assertRaises(ValueError): - verify_prefix_set(ITEST, 'ITEST', 't') + dut.verify_prefix_set(dut.ITEST, 'ITEST', 't') with self.assertRaises(ValueError): - verify_prefix_set(ITEST, '', '') + dut.verify_prefix_set(dut.ITEST, '', '') with self.assertRaises(ValueError): - verify_prefix_set(QTEST, '', 't') + dut.verify_prefix_set(dut.QTEST, '', 't') if __name__ == '__main__':