Author: gnichols
Date: 2010-03-04 18:58:36 +0000 (Thu, 04 Mar 2010)
New Revision: 407
Modified:
trunk/v7/documentbase.py
trunk/v7/hardwaretest.py
trunk/v7/rundocument.py
trunk/v7/tags.py
trunk/v7/test.py
Log:
555895 - FEAT: results.xml could divide out the various sub tests.
Modified: trunk/v7/documentbase.py
===================================================================
--- trunk/v7/documentbase.py 2010-03-04 18:56:19 UTC (rev 406)
+++ trunk/v7/documentbase.py 2010-03-04 18:58:36 UTC (rev 407)
@@ -83,6 +83,15 @@
textNode = self.document.createTextNode(value)
element.appendChild(textNode)
+ def addTextNode(self, element, value):
+ if value:
+ if type(value) == unicode:
+ value = value.encode('ascii')
+ value = self.removeBadCharacters(value)
+
+ textNode = self.document.createTextNode(value)
+ element.appendChild(textNode)
+
def getTextNode(self, element):
for node in element.childNodes:
if node.nodeType == node.TEXT_NODE:
@@ -188,11 +197,11 @@
print "Error: unknown device source %s" % source
raise Exception("Error: unknown device source %s"% source)
- def merge(self, documentFilePath):
+ def merge(self, documentFilePath, nodeIndex=1):
subdocument = DocumentBase()
subdocument.load(documentFilePath)
try:
- root = self.document.importNode(subdocument.document.childNodes[1], True) #
True = deep copy
+ root = self.document.importNode(subdocument.document.childNodes[nodeIndex],
True) # True = deep copy
self.element.appendChild(root)
except Exception, e:
print "Error: could not import document in " + documentFilePath
Modified: trunk/v7/hardwaretest.py
===================================================================
--- trunk/v7/hardwaretest.py 2010-03-04 18:56:19 UTC (rev 406)
+++ trunk/v7/hardwaretest.py 2010-03-04 18:58:36 UTC (rev 407)
@@ -947,13 +947,8 @@
def saveOutput(self, run, retval, outputFilePath):
print "saveOutput: %s" % outputFilePath
- outputFile = open(outputFilePath)
- contents = ""
- for line in outputFile:
- contents += line
- contents += "\n" #make sure there's a line break at the end.
run.setReturnValue(retval)
- run.setTestOutput(contents)
+ run.setTestOutput(outputFilePath)
def _getTestsFromOptions(self):
if self.options.device:
Modified: trunk/v7/rundocument.py
===================================================================
--- trunk/v7/rundocument.py 2010-03-04 18:56:19 UTC (rev 406)
+++ trunk/v7/rundocument.py 2010-03-04 18:58:36 UTC (rev 407)
@@ -14,7 +14,7 @@
#
# Author: Greg Nichols
#
-import string, os
+import string, os, re
import time
from xml.dom.minidom import getDOMImplementation, parse
import xml.dom.ext
@@ -122,22 +122,71 @@
systemElement = self.findOrCreateElement(self.element, Tags.system)
self.setTextNode(systemElement, log)
+ def getTestOutput(self):
+ return self.__getTestOutput(self.getChildElement(Tags.output))
- def getTestOutput(self):
- try:
- outputElement = self.getChildElement(Tags.output)
- if outputElement:
- return outputElement.childNodes[0].data
- #otherwise
- return None
- except IndexError:
- return None
+ def __getTestOutput(self, outputElement):
+ output = ""
+ for node in outputElement.childNodes:
+ if node.nodeType == node.ELEMENT_NODE and node.tagName == Tags.output:
+ output += "\nSection %s " % node.getAttribute(Attributes.name)
+ if node.getAttribute(Attributes.description):
+ output += " - " +
node.getAttribute(Attributes.description)
+ output += "\n"
+ output += self.__getTestOutput(node)
+ output += "End Section\n"
+ elif node.nodeType == node.TEXT_NODE:
+ output += node.data
+ return output
- def setTestOutput(self, output):
+ def setTestOutputXXX(self, output):
+ print "NEW setTestOutput"
if output:
outputElement = self.findOrCreateElement(self.element, Tags.output)
- textNode = self.setTextNode(outputElement, output)
+ section = ""
+ outputElements = list()
+ pattern = re.compile("<output(
name=\"(?P<name>[^\"]*)\")?(
description=\"(?P<description>[^\"]*)\")?>")
+ for line in output:
+ print "LINE: " + line
+ match = pattern.match(line)
+ if match:
+ print "MATCHED: " + line
+ textNode = self.setTextNode(outputElement, section)
+ section = ""
+ outputElements.append(outputElement)
+ child = self.document.createElement(Tags.output)
+ outputElement.appendChild(child)
+ outputElement = child
+ outputElement.setAttribute(Attributes.name,
match.group(Attributes.name))
+ outputElement.setAttribute(Attributes.description,
match.group(Attributes.description))
+ elif "</output>" in line:
+ self.setTextNode(outputElement, section)
+ section = ""
+ outputElement = outputElements.pop()
+ else:
+ section += line
+
+ textNode = self.addTextNode(outputElement, section)
+
+ def setTestOutput(self, outputFile):
+ try:
+ self.merge(outputFile, nodeIndex=0)
+ return True
+ except Exception, e:
+ print "Warning: could not merge output XML, reading as text file."
+ print e
+
+ # parser failed, just read the file
+ file = open(outputFile)
+ output = file.readlines()
+ if output and len(output) < 0:
+ outputElement = self.findOrCreateElement(self.element, Tags.output)
+ textNode = self.setTextNode(outputElement, output.join())
+ return True
+
+
+
def getResults(self, environment, resultsFile):
try:
file = open(resultsFile, "r")
@@ -210,6 +259,10 @@
except Exception, e:
print "Error: "
print e
+
+ def deleteAttachments(self):
+ for attachment in self.getAttachments():
+ self.runElement.removeChild(attachment)
Modified: trunk/v7/tags.py
===================================================================
--- trunk/v7/tags.py 2010-03-04 18:56:19 UTC (rev 406)
+++ trunk/v7/tags.py 2010-03-04 18:58:36 UTC (rev 407)
@@ -86,6 +86,7 @@
function="function"
task_file="task_file"
maximum_attachment_size="maximum-attachment-size"
+ description="description"
Modified: trunk/v7/test.py
===================================================================
--- trunk/v7/test.py 2010-03-04 18:56:19 UTC (rev 406)
+++ trunk/v7/test.py 2010-03-04 18:58:36 UTC (rev 407)
@@ -49,6 +49,7 @@
self.logicalDeviceName = ""
self.mandatory = None # either pre or post for mandatory tests (for each run)
self.source = None # either hal, kudzu, or manual
+ self.marking = False # is <output> sub-section currently active?
try:
self.outputFile = os.environ[Constants.OUTPUTFILE]
@@ -400,3 +401,31 @@
"""Test should implement this method if they have package
requirements dependant on hardware or RHEL release"""
return list()
+
+ def markOutput(self, name, description=None):
+ self.closeOutput()
+ print "<output name=\"%s\"
description=\"%s\">" % (name, description)
+ self.marking = True
+
+ def closeOutput(self):
+ if self.marking:
+ print "</output>"
+ self.marking = False
+
+ def markSummary(self, summary):
+ if type(summary) is str:
+ summaryString = summary
+ elif summary:
+ summaryString = Constants.PASS
+ else:
+ summaryString = Constants.FAIL
+ print "<summary>%s</summary>" % summaryString
+
+ def runSubTest(self, subtestFunction, name, description=None):
+ self.markOutput(name, description)
+ result = subtestFunction()
+ self.markSummary(result)
+ self.closeOutput()
+ return result
+
+