Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import libxml2
- import libxslt
- jsunit_files = []
- xunit_files = []
- files_to_create = []
- docText = """<?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
- xmlns:lxslt="http://xml.apache.org/xslt"
- xmlns:redirect="http://xml.apache.org/xalan/redirect"
- xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils"
- extension-element-prefixes="redirect">
- <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
- <xsl:template match="browserResult">
- <xsl:variable name="browser" select="browser/displayName" />
- <testsuites>
- <xsl:variable name="numberOfTests" select="count(descendant::testCaseResult)" />
- <xsl:variable name="numberOfErrors" select="count(descendant::error)" />
- <xsl:variable name="numberOfFailures" select="count(descendant::failure)" />
- <xsl:variable name="hostName" select="properties/property[@name = 'remoteAddress']/@value" />
- <xsl:variable name="testSuiteName" select="properties/property[@name = 'testPage']/@value" />
- <xsl:variable name="totalTime" select='format-number(sum(descendant::testCaseResult/@time), "#.###")' />
- <testsuite errors="{$numberOfErrors}" failures="{$numberOfFailures}" hostname="{$hostName}" name="{$browser}.{$testSuiteName}" tests="{$numberOfTests}" time="{$totalTime}">
- <xsl:copy-of select="properties" /> <!-- copy all properties -->
- <xsl:for-each select="testCaseResults/testCaseResult">
- <xsl:variable name="classname">
- <xsl:call-template name="get-classname">
- <xsl:with-param name="testname" select="substring-before(@name,'.html:')"/>
- </xsl:call-template>
- </xsl:variable>
- <testcase classname="JsUnit.{$browser}.{$classname}" name="{substring-after(@name,'.html:')}" time="{@time}">
- <xsl:copy-of select="*" /> <!-- copy all failures and errors -->
- </testcase>
- </xsl:for-each>
- </testsuite>
- </testsuites>
- </xsl:template>
- <!-- recursively strips slashes from the beginning until none are left -->
- <xsl:template name="get-classname">
- <xsl:param name="testname" />
- <xsl:choose>
- <xsl:when test="contains($testname, '/')">
- <xsl:call-template name="get-classname">
- <xsl:with-param name="testname" select="substring-after($testname, '/')" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$testname" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- </xsl:stylesheet>
- """
- # Load up the transformation
- styleDoc = libxml2.parseDoc(docText)
- style = libxslt.parseStylesheetDoc(styleDoc)
- # Get the files that have been generated by jsunit
- for test_file in os.listdir(os.path.dirname(__file__)):
- file_name = os.path.basename(test_file)
- if file_name.startswith('JSTEST-'):
- jsunit_files.append(file_name)
- elif file_name.startswith('XUNIT-'):
- xunit_files.append(file_name)
- # Strip out the files that have already been converted from jsunit to xunit
- for xunit_file in xunit_files:
- if 'JSTEST-' + xunit_file[6:] in jsunit_files:
- jsunit_files.remove('JSTEST-' + xunit_file[6:])
- # Create the new xunit files
- for jsunit_file in jsunit_files:
- new_file = 'XUNIT-' + jsunit_file[7:]
- doc = libxml2.parseDoc(open(os.path.join(os.path.dirname(__file__), jsunit_file)).read())
- save_to = open(os.path.join(os.path.dirname(__file__), new_file), 'w')
- xml = style.saveResultToString(style.applyStylesheet(doc,{}))
- # Write out the transformed xml, stripping out any cruft
- save_to.write(xml[:xml.index("?>") + 2] + xml[xml.index("<testsuites"):])
- save_to.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement