def test_ProceedingsToXMLWriter(self): """ Testing the correctness of the ProceedingsToXMLWriter class. The following test cases are covered: 1. Calling a ProceedingsToXMLWriter with a wrong parameter 1.a None 1.b an integer value 2. Calling the ProceedintsToXMLWriter with a correct parameter """ wrtr = ProceedingsToXMLWriter() #1.a strRepresentation = wrtr.createXMLFromProceedings(None) self.assertEqual(strRepresentation, None) #1.b strRepresentation = wrtr.createXMLFromProceedings(1) self.assertEqual(strRepresentation, None) #2 prcdngs = Proceedings(self.testTask, self.testTimeStamp) strRepresentation = wrtr.createXMLFromProceedings(prcdngs).toxml() expectedOutput = "<?xml version=\"1.0\" ?><proceedings><timestamp>201405161350</timestamp><task>PrettyTestTask</task><waiting><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry></waiting><running/><completed/><error/></proceedings>" self.assertEqual(expectedOutput, strRepresentation,"Output of XML-file did not match what we wanted to have")
def test_ProceedingsToXMLWriter(self): """ Testing the correctness of the ProceedingsToXMLWriter class. The following test cases are covered: 1. Calling a ProceedingsToXMLWriter with a wrong parameter 1.a None 1.b an integer value 2. Calling the ProceedintsToXMLWriter with a correct parameter """ wrtr = ProceedingsToXMLWriter() #1.a strRepresentation = wrtr.createXMLFromProceedings(None) self.assertEqual(strRepresentation, None) #1.b strRepresentation = wrtr.createXMLFromProceedings(1) self.assertEqual(strRepresentation, None) #2 prcdngs = Proceedings(self.testTask, self.testTimeStamp) strRepresentation = wrtr.createXMLFromProceedings(prcdngs).toxml() expectedOutput = "<?xml version=\"1.0\" ?><proceedings><timestamp>201405161350</timestamp><task>PrettyTestTask</task><waiting><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI1</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI2</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI3</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas1</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas2</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas3</computeralgebrasystem></entry><entry><probleminstance>PI4</probleminstance><computeralgebrasystem>cas4</computeralgebrasystem></entry></waiting><running/><completed/><error/></proceedings>" self.assertEqual( expectedOutput, strRepresentation, "Output of XML-file did not match what we wanted to have")
def createXMLFromResultedTimings(self, resultedTimings): """ Returns an XML-Representation of the ResultedTimings. This representation has the following form:: <proceedings> <timestamp> "The timestamp" </timestamp> <task> "the name of the executed task" </task> <running> <entry> <probleminstance> "A problem instance" </probleminstance> <computeralgebrasystem> "A computer algebra system" </computeralgebrasystem> </entry> </running> <waiting> "same as running" </waiting> <completed> "same as running, but with" <timings> <real> "real time" </real> <user> "user time" </user> <sys> "sys time" </sys> </timings> </completed> <error> "same as completed" </error> </proceedings> If resultedTimings is not a proper ResultedTimings-instance, None is returned. :param resultedTimings: The proceedings we want to have the xml representation of :type resultedTimings: Proceedings :returns: An xml-representation of the proceedings :rtype: xml.dom.minidom.Document """ if not isinstance(resultedTimings, ResultedTimings): return None if resultedTimings == None: return None writer = ProceedingsToXMLWriter() result = writer.createXMLFromProceedings(resultedTimings.getProceedings()) #First the completed completed = result.getElementsByTagName("completed")[0] entries = completed.getElementsByTagName("entry") for e in entries: pi = (e.getElementsByTagName("probleminstance")[0]).firstChild.data cas = (e.getElementsByTagName("computeralgebrasystem")[0]).firstChild.data d = resultedTimings.getResultingFileDict()[str([pi,cas])] timingsNode = e.appendChild(result.createElement("timings")) for k in d: tempNode = timingsNode.appendChild(result.createElement(k)) tempNode.appendChild(result.createTextNode(d[k])) #Now the ERROR files errors = result.getElementsByTagName("error")[0] entries = errors.getElementsByTagName("entry") for e in entries: pi = (e.getElementsByTagName("probleminstance")[0]).firstChild.data cas = (e.getElementsByTagName("computeralgebrasystem")[0]).firstChild.data d = resultedTimings.getResultingFileDict()[str([pi,cas])] timingsNode = e.appendChild(result.createElement("timings")) for k in d: tempNode = timingsNode.appendChild(result.createElement(k)) tempNode.appendChild(result.createTextNode(d[k])) return result