Skip to content

Commit

Permalink
Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Jun 3, 2024
1 parent 62bcb1b commit af77d9f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 616 deletions.
82 changes: 81 additions & 1 deletion doc/Unittesting/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,84 @@
Unittesting
###########

.. todo:: Write Unittesting introduction.
*pyEDAA.Reports* provides a unified and generic unittest summary data model. The data model allows the description of
testcases grouped in testsuites. Testsuites can be nested in other testsuites. The data model's root element is a
special testsuite called testsuite summary. It contains only testsuites, but no testcases.

.. todo:: UNIT:: Add data model diagram

The data model can be filled from various sources like **Ant JUnit test reports** or **OSVVM testsuite summaries** (more
to be added). Many programming languages and/or unit testing frameworks support exporting results in the Ant JUnit
format. See below for supported formats and their variations.

.. attention::

The so called JUnit XML format is the weakest file format and standard ever seen. At first it was not created. At
first was not created by JUnit (version 4). It was added by the built system Ant, but it's not called Ant XML format
nor Ant JUnit XML format. The latest JUnit 5 uses a completely different format called open test reporting. As JUnit
is not the formats author, no file format documentation nor XML schema was provided. Also Ant isn't providing any
file format documentation or XML schema. Various Ant JUnit XML adopters have tried to reverse engineer a description
and XML schemas, but unfortunately many are not even compatible to each other.

.. todo::

https://github.com/ota4j-team/open-test-reporting

.. admonition:: default box

test text

.. rubric:: Supported Ant JUnit XMl file outputs

* pytest
* VUnit
* OSVVM (OSVVM's YAML format should be preferred due to more content and meta information)

.. rubric:: Supported proprietary file formats

* OSVVM (YAML files)


File Formats
************

Ant and JUnit 4 XML
===================


JUnit 5 XML
===========


OSVVM YAML
==========


Frameworks
**********

JUnit
=====


OSVVM
=====


pytest
======


VUnit
=====


Consumers
*********

Jenkins
=======


Dorney
======
14 changes: 14 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ Proposal to define an abstract model for outputs from EDA tools and logging libr

<br>


.. rubric:: Supported Ant JUnit XMl file outputs

* pytest
* VUnit
* OSVVM (OSVVM's YAML format should be preferred due to more content and meta information)

.. rubric:: Supported proprietary file formats

* OSVVM (YAML files)




.. _contributors:

Contributors
Expand Down
36 changes: 17 additions & 19 deletions pyEDAA/Reports/CLI/Unittesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,31 @@ def _merge(self, testsuiteSummary: MergedTestsuiteSummary, task: str) -> None:
elif l == 2:
dialect, format = (x.lower() for x in parts[0].split("-"))
globPattern = parts[1]

foundFiles = tuple(f for f in Path.cwd().glob(globPattern))
if len(foundFiles) == 0:
self.WriteWarning(f"Found no matching files for pattern '{Path.cwd()}/{globPattern}'")
return

if format == "junit":
if dialect == "ant":
self._mergeAntJUnit(testsuiteSummary, globPattern)
self._mergeAntJUnit(testsuiteSummary, foundFiles)
elif dialect == "ctest":
self._mergeCTestJUnit(testsuiteSummary, globPattern)
self._mergeCTestJUnit(testsuiteSummary, foundFiles)
elif dialect == "gtest":
self._mergeGoogleTestJUnit(testsuiteSummary, globPattern)
self._mergeGoogleTestJUnit(testsuiteSummary, foundFiles)
elif dialect == "pytest":
self._mergePyTestJUnit(testsuiteSummary, globPattern)
self._mergePyTestJUnit(testsuiteSummary, foundFiles)
else:
self.WriteError(f"Unsupported JUnit XML dialect for merging: '{format}'")
else:
self.WriteError(f"Unsupported unit testing report format for merging: '{format}'")
else:
self.WriteError(f"Syntax error: '{task}'")

def _mergeAntJUnit(self, testsuiteSummary: MergedTestsuiteSummary, globPattern: str) -> None:
from pyEDAA.Reports.Unittesting.JUnit.AntJUnit import Document, JUnitReaderMode
def _mergeAntJUnit(self, testsuiteSummary: MergedTestsuiteSummary, foundFiles: Tuple[Path]) -> None:
from pyEDAA.Reports.Unittesting.JUnit.AntJUnit import Document

foundFiles = [f for f in Path.cwd().glob(globPattern)]
self.WriteNormal(f"Reading {len(foundFiles)} Ant-JUnit unit test summary files ...")

junitDocuments: List[Document] = []
Expand All @@ -100,10 +105,9 @@ def _mergeAntJUnit(self, testsuiteSummary: MergedTestsuiteSummary, globPattern:
self.WriteVerbose(f" merging {summary.Path}")
testsuiteSummary.Merge(summary.ToTestsuiteSummary())

def _mergeCTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, globPattern: str) -> None:
from pyEDAA.Reports.Unittesting.JUnit.CTestJUnit import Document, JUnitReaderMode
def _mergeCTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, foundFiles: Tuple[Path]) -> None:
from pyEDAA.Reports.Unittesting.JUnit.CTestJUnit import Document

foundFiles = [f for f in Path.cwd().glob(globPattern)]
self.WriteNormal(f"Reading {len(foundFiles)} CTest-JUnit unit test summary files ...")

junitDocuments: List[Document] = []
Expand All @@ -116,10 +120,9 @@ def _mergeCTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, globPattern
self.WriteVerbose(f" merging {summary.Path}")
testsuiteSummary.Merge(summary.ToTestsuiteSummary())

def _mergeGoogleTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, globPattern: str) -> None:
from pyEDAA.Reports.Unittesting.JUnit.GoogleTestJUnit import Document, JUnitReaderMode
def _mergeGoogleTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, foundFiles: Tuple[Path]) -> None:
from pyEDAA.Reports.Unittesting.JUnit.GoogleTestJUnit import Document

foundFiles = [f for f in Path.cwd().glob(globPattern)]
self.WriteNormal(f"Reading {len(foundFiles)} GoogleTest-JUnit unit test summary files ...")

junitDocuments: List[Document] = []
Expand All @@ -132,14 +135,9 @@ def _mergeGoogleTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, globPa
self.WriteVerbose(f" merging {summary.Path}")
testsuiteSummary.Merge(summary.ToTestsuiteSummary())

def _mergePyTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, globPattern: str) -> None:
def _mergePyTestJUnit(self, testsuiteSummary: MergedTestsuiteSummary, foundFiles: Tuple[Path]) -> None:
from pyEDAA.Reports.Unittesting.JUnit.PyTestJUnit import Document

foundFiles = [f for f in Path.cwd().glob(globPattern)]
if len(foundFiles) == 0:
self.WriteWarning(f"Found no matching files for pattern '{Path.cwd()}/{globPattern}'")
return

self.WriteNormal(f"Reading {len(foundFiles)} pytest-JUnit unit test summary files ...")

junitDocuments: List[Document] = []
Expand Down
Loading

0 comments on commit af77d9f

Please sign in to comment.