Skip to content

Commit

Permalink
Import xunit2rst as dut
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperCraeghs committed Jan 12, 2024
1 parent 99168b3 commit 7f6e861
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
6 changes: 3 additions & 3 deletions tests/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/mako_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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])
Expand Down
88 changes: 44 additions & 44 deletions tests/prefix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@
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'


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-')

Expand All @@ -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):
Expand All @@ -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__':
Expand Down

0 comments on commit 7f6e861

Please sign in to comment.