diff --git a/mlx/unity2junit/unity2junit.py b/mlx/unity2junit/unity2junit.py index 282c70e..87dccd5 100755 --- a/mlx/unity2junit/unity2junit.py +++ b/mlx/unity2junit/unity2junit.py @@ -59,8 +59,8 @@ def generate_junit_xml(self): timestamp = datetime.now(datetime.timezone.utc).isoformat() # Create a default testsuite using extracted filename - ET.SubElement(testsuites, "testsuite", name=self.default_suite_name, errors="0", tests=self.total_tests, - failures=self.failures, skipped=self.skipped, timestamp=timestamp) + ET.SubElement(testsuites, "testsuite", name=self.default_suite_name, errors="0", tests=str(self.total_tests), + failures=str(self.failures), skipped=str(self.skipped), timestamp=timestamp) for case in self.test_cases: testsuite = ET.SubElement( @@ -82,6 +82,7 @@ def generate_junit_xml(self): ) tree = ET.ElementTree(testsuites) + ET.indent(tree, space=" ", level=0) tree.write(self.output_file, encoding="utf-8", xml_declaration=True) print(f"JUnit XML report generated: {self.output_file}") diff --git a/tests/test_in/utest_Init_Runner.xml b/tests/test_in/utest_Init_Runner.xml new file mode 100644 index 0000000..be739da --- /dev/null +++ b/tests/test_in/utest_Init_Runner.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/unity_parsing_test.py b/tests/unity_parsing_test.py index 9095048..70ff21b 100644 --- a/tests/unity_parsing_test.py +++ b/tests/unity_parsing_test.py @@ -2,8 +2,9 @@ ''' Test suite for functions that set the prefix and prefix_set variables ''' import unittest import tempfile +from unittest.mock import patch from pathlib import Path - +from datetime import datetime, timezone from mlx.unity2junit.unity2junit import Unity2Junit TEST_IN_DIR = Path(__file__).parent / 'test_in' @@ -122,6 +123,25 @@ def test_parsing_unity_log_and_building_testcases_failed(self): self.assertEqual(converter.failures, 1) self.assertEqual(converter.skipped, 0) + def test_init_runner_output(self): + '''Verify that utest_Init_Runner.log is converted to utest_Init_Runner.xml on a fixed timestamp of + 2025-09-25T13:40:24.403458+00:00''' + fixed_timestamp_str = "2025-09-25T13:40:24.403458" # Taken from utest_Init_Runner.xml + fixed_datetime = datetime.fromisoformat(fixed_timestamp_str).replace(tzinfo=timezone.utc) + expected_xml = '' + + with open(TEST_IN_DIR / 'utest_Init_Runner.xml', 'r', encoding='utf-8') as f: + expected_xml = f.readlines() + + with tempfile.NamedTemporaryFile(mode='w+', delete=True, encoding='utf-8') as tmp_output_file: + with patch('mlx.unity2junit.unity2junit.datetime') as mock_dt: + mock_dt.now.return_value = fixed_datetime + converter = Unity2Junit(TEST_IN_DIR / 'utest_Init_Runner.log', tmp_output_file.name) + converter.convert() + tmp_output_file.seek(0) + generated_xml = tmp_output_file.readlines() + self.assertListEqual(generated_xml, expected_xml) + if __name__ == '__main__': unittest.main() diff --git a/tox.ini b/tox.ini index b9a68b9..8c8ff4a 100644 --- a/tox.ini +++ b/tox.ini @@ -53,7 +53,7 @@ deps= {[testenv]deps} sphinx sphinx_rtd_theme - mlx.warnings >= 5.0.0 + mlx.warnings >= 6.1.1 allowlist_externals = bash make