diff --git a/tests/app/GitHub/Examples.py b/tests/app/GitHub/Examples.py index 89642d03..bd02942e 100644 --- a/tests/app/GitHub/Examples.py +++ b/tests/app/GitHub/Examples.py @@ -29,8 +29,16 @@ # ==================================================================================================================== # # """Testcase for application testing report files generated on GitHub.""" -from pathlib import Path -from unittest import TestCase +from pathlib import Path +from unittest import TestCase + +from pyTooling.Common import zipdicts + +# FIXME: change to generic JUnit +from pyEDAA.Reports.Unittesting.JUnit.AntJUnit4 import Document as JUnit4Document +from pyEDAA.Reports.Unittesting.JUnit.CTestJUnit import Document as CTestDocument +from pyEDAA.Reports.Unittesting.JUnit.GoogleTestJUnit import Document as GTestDocument +from pyEDAA.Reports.Unittesting.JUnit.PyTestJUnit import Document as PyTestDocument if __name__ == "__main__": # pragma: no cover @@ -39,6 +47,81 @@ exit(1) -class Dummy(TestCase): - def test_dummy(self): +class CppGoogleTest(TestCase): + def test_gtest(self): + print() + + junitExampleFile = Path("tests/data/JUnit/pyEDAA.Reports/Cpp-GoogleTest/gtest.xml") + doc = GTestDocument(junitExampleFile, analyzeAndConvert=True) + + self.assertEqual(1, doc.TestsuiteCount) + self.assertEqual(3, doc.TestcaseCount) + + print(f"JUnit file:") + print(f" Testsuites: {doc.TestsuiteCount}") + print(f" Testcases: {doc.TestcaseCount}") + + print() + print(f"Statistics:") + print(f" Times: parsing by lxml: {doc.AnalysisDuration.total_seconds():.3f}s convert: {doc.ModelConversionDuration.total_seconds():.3f}s") + + def test_ReadWrite(self): + print() + + junitExampleFile = Path("tests/data/JUnit/pyEDAA.Reports/Cpp-GoogleTest/gtest.xml") + doc = GTestDocument(junitExampleFile, analyzeAndConvert=True) + + junitOutputFile = Path("tests/output/JUnit/pyEDAA.Reports/Cpp-GoogleTest/gtest.xml") + junitOutputFile.parent.mkdir(parents=True, exist_ok=True) + doc.Write(junitOutputFile, regenerate=True, overwrite=True) + + sameDoc = GTestDocument(junitOutputFile, analyzeAndConvert=True) + + self.assertEqual(doc.TestsuiteCount, sameDoc.TestsuiteCount) + self.assertEqual(doc.TestcaseCount, sameDoc.TestcaseCount) + self.assertEqual(doc.Errored, sameDoc.Errored) + self.assertEqual(doc.Skipped, sameDoc.Skipped) + self.assertEqual(doc.Failed, sameDoc.Failed) + self.assertEqual(doc.Passed, sameDoc.Passed) + self.assertEqual(doc.Tests, sameDoc.Tests) + + for tsName, ts, sameTS in zipdicts(doc._testsuites, sameDoc._testsuites): + self.assertEqual(ts.Name, sameTS.Name) + self.assertEqual(ts.Duration, sameTS.Duration) + self.assertEqual(ts.TestcaseCount, sameTS.TestcaseCount) + self.assertEqual(ts.AssertionCount, sameTS.AssertionCount) + self.assertEqual(ts.Errored, sameTS.Errored) + self.assertEqual(ts.Skipped, sameTS.Skipped) + self.assertEqual(ts.Failed, sameTS.Failed) + self.assertEqual(ts.Passed, sameTS.Passed) + self.assertEqual(ts.Tests, sameTS.Tests) + + for tclsName, tcls, sameTCls in zipdicts(ts._testclasses, sameTS._testclasses): + self.assertEqual(tcls.Name, sameTCls.Name) + self.assertEqual(tcls.Classname, sameTCls.Classname) + self.assertEqual(tcls.TestcaseCount, sameTCls.TestcaseCount) + self.assertEqual(tcls.AssertionCount, sameTCls.AssertionCount) + + for tcName, tc, sameTC in zipdicts(tcls._testcases, sameTCls._testcases): + self.assertEqual(tc.Name, sameTC.Name) + self.assertEqual(tc.Classname, sameTC.Classname) + self.assertEqual(tc.Status, sameTC.Status) + self.assertEqual(tc.Duration, sameTC.Duration) + self.assertEqual(tc.AssertionCount, sameTC.AssertionCount) + + +class CppGoogleTestCTest(TestCase): + def test_ctest(self): + print() + + junitExampleFile = Path("tests/data/JUnit/pyEDAA.Reports/Cpp-GoogleTest/ctest.xml") + doc = CTestDocument(junitExampleFile, analyzeAndConvert=True) + + # self.assertEqual(1, doc.TestsuiteCount) + # self.assertEqual(3, doc.TestcaseCount) + + print(f"JUnit file:") + print(f" Testsuites: {doc.TestsuiteCount}") + print(f" Testcases: {doc.TestcaseCount}") + print()