Skip to content

Commit

Permalink
More finetuning of xslt
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Jun 21, 2022
1 parent 5b61b56 commit 097ac7a
Show file tree
Hide file tree
Showing 67 changed files with 17,159 additions and 54 deletions.
6 changes: 3 additions & 3 deletions python/publish/junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ def create_junitxml(filepath: str, tree: JUnitTree) -> Union[JUnitXml, JUnitXmlE
for suite in (junit if junit._tag == "testsuites" else [junit])]

suite_tests = sum([suite.tests for result_file, suite in suites if suite.tests])
suite_skipped = sum([suite.skipped + suite.disabled for result_file, suite in suites if suite.skipped])
suite_failures = sum([suite.failures for result_file, suite in suites if suite.failures])
suite_errors = sum([suite.errors for result_file, suite in suites if suite.errors])
suite_skipped = sum([suite.skipped + suite.disabled for result_file, suite in suites if suite.skipped and not math.isnan(suite.skipped)])
suite_failures = sum([suite.failures for result_file, suite in suites if suite.failures and not math.isnan(suite.failures)])
suite_errors = sum([suite.errors for result_file, suite in suites if suite.errors and not math.isnan(suite.errors)])
suite_time = int(sum([suite.time for result_file, suite in suites
if suite.time and not math.isnan(suite.time)]) * time_factor)

Expand Down
6 changes: 3 additions & 3 deletions python/publish/nunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from publish.junit import JUnitTreeOrException, ParsedJUnitFile

with (pathlib.Path(__file__).parent / 'xslt' / 'nunit-to-junit.xslt').open('r', encoding='utf-8') as r:
with (pathlib.Path(__file__).parent / 'xslt' / 'nunit3-to-junit.xslt').open('r', encoding='utf-8') as r:
transform_nunit_to_junit = etree.XSLT(etree.parse(r))


Expand All @@ -21,8 +21,8 @@ def parse(path: str) -> JUnitTreeOrException:
return Exception(f'File is empty.')

try:
trx = etree.parse(path)
return transform_nunit_to_junit(trx)
nunit = etree.parse(path)
return transform_nunit_to_junit(nunit)
except BaseException as e:
return e

Expand Down
147 changes: 147 additions & 0 deletions python/publish/xslt/nunit3-to-junit.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- based on https://github.com/nunit/nunit-transforms/blob/caadb5442cb1da0a3ade5a03cf169c3e1a13ac57/nunit3-junit/nunit3-junit.xslt -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/test-run | /test-results">
<xsl:variable name="skipped">
<xsl:choose>
<xsl:when test="@skipped"><xsl:value-of select="@skipped"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="not-run">
<xsl:choose>
<xsl:when test="@not-run"><xsl:value-of select="@not-run"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ignored">
<xsl:choose>
<xsl:when test="@ignored"><xsl:value-of select="@ignored"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<testsuites tests="{@testcasecount | @total}" failures="{@failed | @failures}" skipped="{$skipped + $not-run + $ignored}">
<xsl:if test="@errors">
<xsl:attribute name="errors"><xsl:value-of select="@errors"/></xsl:attribute>
</xsl:if>
<xsl:if test="@duration">
<xsl:attribute name="time"><xsl:value-of select="@duration"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</testsuites>
</xsl:template>

<xsl:template match="test-suite">
<xsl:choose>
<xsl:when test="test-case or results/test-case">
<testsuite>
<xsl:if test="@testcasecount">
<xsl:attribute name="tests"><xsl:value-of select="@testcasecount"/></xsl:attribute>
</xsl:if>
<xsl:if test="@failed">
<xsl:attribute name="failures"><xsl:value-of select="@failed"/></xsl:attribute>
</xsl:if>
<xsl:if test="@errors">
<xsl:attribute name="errors"><xsl:value-of select="@errors"/></xsl:attribute>
</xsl:if>
<xsl:if test="@skipped">
<xsl:attribute name="skipped"><xsl:value-of select="@skipped"/></xsl:attribute>
</xsl:if>
<xsl:if test="@duration or @time">
<xsl:attribute name="time">
<xsl:choose>
<xsl:when test="@duration"><xsl:value-of select="@duration"/></xsl:when>
<xsl:when test="@time"><xsl:value-of select="@time"/></xsl:when>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:if test="@start-time">
<xsl:attribute name="timestamp"><xsl:value-of select="@start-time"/></xsl:attribute>
</xsl:if>
<xsl:attribute name="name">
<xsl:choose>
<xsl:when test="@fullname"><xsl:value-of select="@fullname"/></xsl:when>
<xsl:when test="@classname"><xsl:value-of select="@classname"/></xsl:when>
<xsl:otherwise>
<xsl:for-each select="ancestor::test-suite[@type='TestSuite' or @type='Namespace']/@name">
<xsl:value-of select="concat(., '.')"/>
</xsl:for-each>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="test-case | results/test-case"/>
</testsuite>
<xsl:apply-templates select="test-suite"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="test-case">
<testcase name="{@name}" classname="{classname}">
<xsl:if test="@result">
<xsl:attribute name="status"><xsl:value-of select="@result"/></xsl:attribute>
</xsl:if>
<xsl:if test="@assertions">
<xsl:attribute name="assertions"><xsl:value-of select="@assertions"/></xsl:attribute>
</xsl:if>
<xsl:if test="@duration or @time">
<xsl:attribute name="time">
<xsl:choose>
<xsl:when test="@duration"><xsl:value-of select="@duration"/></xsl:when>
<xsl:when test="@time"><xsl:value-of select="@time"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:if test="@executed = 'False' or @result = 'Skipped' or @result = 'Ignored' or @result = 'NotRunnable' or @result = 'Inconclusive' or @runstate = 'Skipped' or @runstate = 'Ignored' or @runstate = 'NotRunnable'">
<skipped>
<xsl:if test="reason/message != ''"><xsl:attribute name="message"><xsl:value-of select="reason/message"/></xsl:attribute></xsl:if>
</skipped>
</xsl:if>
<xsl:apply-templates/>
</testcase>
</xsl:template>

<xsl:template match="command-line"/>
<xsl:template match="settings"/>
<xsl:template match="filter"/>

<xsl:template match="output">
<system-out>
<xsl:value-of select="."/>
</system-out>
</xsl:template>

<xsl:template match="stack-trace">
</xsl:template>

<xsl:template match="test-case/failure">
<xsl:if test="parent::test-case[not(@result) or @result != 'Error']">
<failure message="{./message}">
<xsl:value-of select="./stack-trace"/>
</failure>
</xsl:if>
<xsl:if test="parent::test-case[@result='Error']">
<error message="{./message}">
<xsl:value-of select="./stack-trace"/>
</error>
</xsl:if>
</xsl:template>

<xsl:template match="test-suite/failure"/>

<xsl:template match="test-case/reason"/>

<xsl:template match="test-case/assertions">
</xsl:template>

<xsl:template match="test-suite/reason"/>

<xsl:template match="properties"/>
</xsl:stylesheet>
4 changes: 2 additions & 2 deletions python/publish/xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def parse(path: str) -> JUnitTreeOrException:
return Exception(f'File is empty.')

try:
trx = etree.parse(path)
return transform_xunit_to_junit(trx)
xunit = etree.parse(path)
return transform_xunit_to_junit(xunit)
except BaseException as e:
return e

Expand Down
41 changes: 25 additions & 16 deletions python/test/files/nunit/mstest/pickles.junit-xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<?xml version='1.0' encoding='utf-8'?>
<testsuites>
<testsuite name="Pickles.TestHarness.AdditionFeature" tests="2" time="0.157" failures="0" errors="0" skipped="0">
<testcase classname="Pickles.TestHarness.AdditionFeature" name="AddingSeveralNumbers(&quot;60&quot;,&quot;70&quot;,&quot;130&quot;,System.String[])" time="0.137"/>
<testcase classname="Pickles.TestHarness.AdditionFeature" name="AddingSeveralNumbers(&quot;40&quot;,&quot;50&quot;,&quot;90&quot;,System.String[])" time="0.009"/>
</testsuite>
<testsuite name="Pickles.TestHarness" tests="2" time="0.724" failures="1" errors="0" skipped="0">
<testcase classname="Pickles.TestHarness" name="AdditionFeature.AddTwoNumbers" time="0.004"/>
<testcase classname="Pickles.TestHarness" name="AdditionFeature.FailToAddTwoNumbers" time="0.028">
<failure>
MESSAGE:

+++++++++++++++++++
STACK TRACE:

<testsuites tests="4" failures="1" skipped="0" errors="0">








<testsuite time="0.724" name="Pickles.TestHarness.AdditionFeature"><testcase name="Pickles.TestHarness.AdditionFeature.AddTwoNumbers" classname="" status="Success" time="0.004">



</testcase><testcase name="Pickles.TestHarness.AdditionFeature.FailToAddTwoNumbers" classname="" status="Failure" time="0.028">



<failure message="">
at Pickles.TestHarness.xUnit.Steps.ThenTheResultShouldBePass(Int32 result) in C:\dev\pickles-results-harness\Pickles.TestHarness\Pickles.TestHarness.NUnit\Steps.cs:line 26
at lambda_method(Closure , IContextManager , Int32 )
at TechTalk.SpecFlow.Bindings.MethodBinding.InvokeAction(IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan&amp; duration)
Expand All @@ -25,6 +29,11 @@ at Pickles.TestHarness.AdditionFeature.ScenarioCleanup() in C:\dev\pickles-resul
at Pickles.TestHarness.AdditionFeature.FailToAddTwoNumbers() in c:\dev\pickles-results-harness\Pickles.TestHarness\Pickles.TestHarness.NUnit\Addition.feature:line 18

</failure>
</testcase>
</testsuite>
</testcase></testsuite>






</testsuites>
37 changes: 7 additions & 30 deletions python/test/files/nunit/mstest/pickles.results
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
publish.unittestresults.ParsedUnitTestResults(
files=1,
errors=[],
suites=2,
suite_tests=4,
suites=1,
suite_tests=2,
suite_skipped=0,
suite_failures=1,
suite_errors=0,
Expand All @@ -12,30 +12,8 @@ publish.unittestresults.ParsedUnitTestResults(
result_file='mstest/pickles.xml',
test_file=None,
line=None,
class_name='Pickles.TestHarness.AdditionFeature',
test_name='AddingSeveralNumbers("60","70","130",System.String[])',
result='success',
message=None,
content=None,
time=0.137
),
publish.unittestresults.UnitTestCase(
result_file='mstest/pickles.xml',
test_file=None,
line=None,
class_name='Pickles.TestHarness.AdditionFeature',
test_name='AddingSeveralNumbers("40","50","90",System.String[])',
result='success',
message=None,
content=None,
time=0.009
),
publish.unittestresults.UnitTestCase(
result_file='mstest/pickles.xml',
test_file=None,
line=None,
class_name='Pickles.TestHarness',
test_name='AdditionFeature.AddTwoNumbers',
class_name='',
test_name='Pickles.TestHarness.AdditionFeature.AddTwoNumbers',
result='success',
message=None,
content=None,
Expand All @@ -45,12 +23,11 @@ publish.unittestresults.ParsedUnitTestResults(
result_file='mstest/pickles.xml',
test_file=None,
line=None,
class_name='Pickles.TestHarness',
test_name='AdditionFeature.FailToAddTwoNumbers',
class_name='',
test_name='Pickles.TestHarness.AdditionFeature.FailToAddTwoNumbers',
result='failure',
message=None,
content='\nMESSAGE:\n\n+++++++++++++++++++\nSTACK TRACE:\n\n '
' at '
content='\n at '
'Pickles.TestHarness.xUnit.Steps.ThenTheResultShouldBePass(Int32 '
'result) in '
'C:\\dev\\pickles-results-harness\\Pickles.TestHarness\\Pickles.TestHarnes'
Expand Down

0 comments on commit 097ac7a

Please sign in to comment.