Beispiel #1
0
    def __init__(self, proceedings=None, task=None, timeStamp=None):
        """
        This is the constructor of the ResultedTimings-Class. Either a proceedings instance is given and
        this will be used then, or a new Proceedings instance is generated given the task and the timeStamp.
        If both are given, the object is created by ignoring the last two input entries.

        :param proceedings: The proceedings instance we want to decorate
        :type  proceedings: Proceedings
        :param      task: The task we want to create the Proceedings instance of
        :type       task: Task
        :param timeStamp: The timestamp of the execution of the task
        :type  timeStamp: string
        :raise   IOError: If neither a Proceedings instance nor a task or a timeStamp is given
        """
        if (proceedings == None and (task == None and timeStamp == None)):
            raise IOError(
                "In ResultedTimings constructor: Neither proceedings, nor a tuple of task and a timestamp are given."
            )
        if proceedings:
            if (not isinstance(proceedings, Proceedings)):
                raise IOError("The given input was not of type Proceedings")
            self.__proceedings = proceedings
        elif task and timeStamp:
            if ((not isinstance(task, Task))
                    or (not isinstance(timeStamp, str))):
                raise IOError(
                    "The given Task was not of correct type, or the timestamp")
            self.__proceedings = Proceedings(task, timeStamp)
        self.__ResultingFileDict = {}
Beispiel #2
0
    def __init__(self, proceedings=None, task=None, timeStamp=None):
        """
        This is the constructor of the ResultedTimings-Class. Either a proceedings instance is given and
        this will be used then, or a new Proceedings instance is generated given the task and the timeStamp.

        :param proceedings: The proceedings instance we want to decorate
        :type  proceedings: Proceedings
        :param      task: The task we want to create the Proceedings instance of
        :type       task: Task
        :param timeStamp: The timestamp of the execution of the task
        :type  timeStamp: string
        :raise   IOError: If neither a Proceedings instance nor a task or a timeStamp is given
        """
        if proceedings:
            self.__proceedings = proceedings
        elif task and timeStamp:
            self.__proceedings = Proceedings(task, timeStamp)
        else:
            raise IOError(
                "In ResultedTimings constructor: Neither proceedings, nor a tuple of task and a timestamp are given."
            )
        self.__ResultingFileDict = {}
Beispiel #3
0
 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")
Beispiel #4
0
 def test_Proceedings(self):
     """
     This tests checks the correctness of the Proceedings class. The following tests are covered:
     1. Creation of Proceedings with None as the task (fail)
     2. Creation of Proceedings with an integer as task (fail)
     3. Creation of Proceedings with None as timestamp (fail)
     4. Creation of Proceedings with an integer as timestamp (fail)
     5. Correct initialization of the proceedings
        5.1. Test the initial set
        5.2. Test the getters
        5.3. Test setRunning with incorrect value
        5.4. Test setRunning with correct value
        5.5. Test setCompleted with incorrect value
        5.6. Test setCompleted with correct value
        5.7. Test setERROR with incorrect value
        5.8. Test setERROR with correct value.
     """
     #1.
     testPassed = 1
     try:
         prcdngs = Proceedings(None, self.testTimeStamp)
         testPassed = 0
     except:
         pass
     if (testPassed == 0):
         self.fail("Could create Proceedings with no Task")
     #2.
     try:
         prcdngs = Proceedings(1, self.testTimeStamp)
         testPassed = 0
     except:
         pass
     if (testPassed == 0):
         self.fail("Could create Proceedings with 1 as Task")
     #3.
     try:
         prcdngs = Proceedings(self.testTask, None)
         testPassed = 0
     except:
         pass
     if (testPassed == 0):
         self.fail("Could create Proceedings with None as timestamp")
     #4.
     try:
         prcdngs = Proceedings(self.testTask, 1)
         testPassed = 0
     except:
         pass
     if (testPassed == 0):
         self.fail("Could create Proceedings with 1 as timestamp")
     #5.
     prcdngs = Proceedings(self.testTask, self.testTimeStamp)
     #5.1
     self.assertEqual(len(prcdngs.getWAITING()), 16,
                      "Number of waiting processes was not correct")
     self.assertEqual(prcdngs.getRUNNING(), [],
                      "Running processes initially wrong")
     self.assertEqual(prcdngs.getCOMPLETED(), [],
                      "Completed processes initially wrong")
     self.assertEqual(prcdngs.getERROR(), [],
                      "Erroneous processes initially wrong")
     #5.2
     self.assertEqual(prcdngs.getTask(), self.testTask.getName(),
                      "Initialization with wrong task performed")
     self.assertEqual(prcdngs.getTimeStamp(), self.testTimeStamp,
                      "Initialization with wrong timeStamp")
     #5.3
     prcdngs.setRUNNING("abc")
     self.assertEqual(len(prcdngs.getWAITING()), 16,
                      "invalid setRunning changed WAITING list.")
     self.assertEqual(prcdngs.getRUNNING(), [],
                      "invalid setRunning changed RUNNING list.")
     self.assertEqual(prcdngs.getCOMPLETED(), [],
                      "invalid setRunning changed COMPLETED list.")
     self.assertEqual(prcdngs.getERROR(), [],
                      "invalid setRunning changed ERROR list.")
     #5.4
     prcdngs.setRUNNING(["PI1", "cas1"])
     self.assertEqual(len(prcdngs.getWAITING()), 15,
                      "setRunning changed WAITING list wrongly.")
     self.assertEqual(prcdngs.getRUNNING(), [["PI1", "cas1"]],
                      "setRunning did not affect RUNNING list.")
     self.assertEqual(prcdngs.getCOMPLETED(), [],
                      "setRunning changed COMPLETED list.")
     self.assertEqual(prcdngs.getERROR(), [],
                      "setRunning changed ERROR list.")
     #5.5
     prcdngs.setCOMPLETED("abc")
     self.assertEqual(len(prcdngs.getWAITING()), 15,
                      "invalid setCompleted changed WAITING list wrongly.")
     self.assertEqual(prcdngs.getRUNNING(), [["PI1", "cas1"]],
                      "invalid setCompleted changed RUNNING list.")
     self.assertEqual(prcdngs.getCOMPLETED(), [],
                      "invalid setCompleted changed COMPLETED list.")
     self.assertEqual(prcdngs.getERROR(), [],
                      "invalid setCompleted changed ERROR list.")
     #5.6
     prcdngs.setCOMPLETED(["PI1", "cas1"])
     self.assertEqual(len(prcdngs.getWAITING()), 15,
                      "setCompleted changed WAITING list.")
     self.assertEqual(prcdngs.getRUNNING(), [],
                      "setCompleted changed RUNNING list wrongly.")
     self.assertEqual(prcdngs.getCOMPLETED(), [["PI1", "cas1"]],
                      "setCompleted did not change COMPLETED list.")
     self.assertEqual(prcdngs.getERROR(), [],
                      "setCompleted changed ERROR list.")
     #5.7
     prcdngs.setERROR(["PI1", "cas1"])
     self.assertEqual(len(prcdngs.getWAITING()), 15,
                      "invalid setERROR changed WAITING list.")
     self.assertEqual(prcdngs.getRUNNING(), [],
                      "invalid setERROR changed RUNNING list.")
     self.assertEqual(prcdngs.getCOMPLETED(), [["PI1", "cas1"]],
                      "invalid setERROR changed COMPLETED list.")
     self.assertEqual(prcdngs.getERROR(), [],
                      "invalid serERROR changed ERROR list.")
     #5.8
     prcdngs.setRUNNING(["PI2", "cas1"])
     prcdngs.setERROR(["PI2", "cas1"])
     self.assertEqual(len(prcdngs.getWAITING()), 14,
                      "setERROR changed WAITING list.")
     self.assertEqual(prcdngs.getRUNNING(), [],
                      "setERROR changed RUNNING list wrongly.")
     self.assertEqual(prcdngs.getCOMPLETED(), [["PI1", "cas1"]],
                      "setERROR changed COMPLETED list.")
     self.assertEqual(prcdngs.getERROR(), [["PI2", "cas1"]],
                      "setERROR changed ERROR list wrongly.")
Beispiel #5
0
    def test_ProceedingsToHTMLWriter(self):
        """
        Testing the correctness of the ProceedingsToHTMLWriter class.
        The following test cases are covered:
        1. Calling a ProceedingsToHTMLWriter with a wrong parameter
           1.a None
           1.b an integer value
        2. Calling the ProceedingsToHTMLWriter with a correct parameter
        """
        wrtr = ProceedingsToHTMLWriter()
        #1.a
        strRepresentation = wrtr.createHTMLFromProceedings(None)
        self.assertEqual(strRepresentation, None)
        #1.b
        strRepresentation = wrtr.createHTMLFromProceedings(1)
        self.assertEqual(strRepresentation, None)
        #2
        prcdngs = Proceedings(self.testTask, self.testTimeStamp)
        expectedOutput = "<html>\n\
<head>\n\
\t<title>PrettyTestTask run at 201405161350</title>\n\
\t<link rel=\"stylesheet\" type=\"text/css\" href=\"proceedings_css.css\">\n\
</head>\n\
<body>\n\
<h1> Task: PrettyTestTask </h1>\n\
<h2> Run at time: 201405161350 </h2>\n\
<br><br>\n\
<table id=\"mainTable\">\n\
\t<tr>\n\
\t\t<td id=\"piAndCAS\"> Problem Instance/Computer Algebra System</td>\n\
\t\t<td id=\"casName\">cas4</td>\n\
\t\t<td id=\"casName\">cas1</td>\n\
\t\t<td id=\"casName\">cas3</td>\n\
\t\t<td id=\"casName\">cas2</td>\n\
\t</tr>\n\
\t<tr>\n\
\t\t<td id=\"piName\">PI1</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t</tr>\n\
\t<tr>\n\
\t\t<td id=\"piName\">PI2</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t</tr>\n\
\t<tr>\n\
\t\t<td id=\"piName\">PI3</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t</tr>\n\
\t<tr>\n\
\t\t<td id=\"piName\">PI4</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t\t<td id=\"waitingCalc\">WAITING</td>\n\
\t</tr>\n\
</table>\n\
</body>\n\
</html>"

        self.assertEqual(wrtr.createHTMLFromProceedings(prcdngs),
                         expectedOutput, "HTML representation was wrong")
    def build(self, xmlRaw, task):
        """
        Returns an instance of Proceedings, given an xml-string and an instance of the associated task.
        The given string is assumed to have 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"
            </completed>
            <error>
              "same as running"
            </error>
          </proceedings>

        An IOError is raised if the XML instance was not valid.
        
        :param    xmlRaw: The xml-representation of the proceedings.
        :type     xmlRaw: string
        :param    task: The task associated to the given proceedings instance.
        :type     task: Task
        :returns: An instance of the Proceedings class
        :rtype:   Proceedings
        """
        try:
            xmlTree = dom.parseString(xmlRaw)
        except:
            raise IOError("Could not parse the given string as XML-Instance")
        try:
            timeStamp = str((xmlTree.getElementsByTagName("timestamp")[0]
                             ).firstChild.data).strip()
        except:
            raise IOError("Given XML instance did not have a timestamp entry")
        result = Proceedings(task, timeStamp)
        try:
            completedCalculations = xmlTree.getElementsByTagName(
                "completed")[0]
            erroneousCalculations = xmlTree.getElementsByTagName("error")[0]
        except:
            raise IOError(
                "Could not find entries for completed resp. erroneous computations"
            )
        #First dealing with all the completed calculations
        tempEntry = completedCalculations.firstChild
        while (tempEntry != None and tempEntry.nodeType == dom.Node.TEXT_NODE):
            tempEntry = tempEntry.nextSibling
        while tempEntry != None:
            try:
                cas = str(
                    (tempEntry.getElementsByTagName("computeralgebrasystem")[0]
                     ).firstChild.data).strip()
                pi = str((tempEntry.getElementsByTagName("probleminstance")[0]
                          ).firstChild.data).strip()
            except:
                raise IOError(
                    "The entries in the list of completed calculations are not valid"
                )
            result.setRUNNING([pi, cas])
            result.setCOMPLETED([pi, cas])
            tempEntry = tempEntry.nextSibling
            while (tempEntry != None
                   and tempEntry.nodeType == dom.Node.TEXT_NODE):
                tempEntry = tempEntry.nextSibling
        #Now dealing with the erroneous calculations
        tempEntry = erroneousCalculations.firstChild
        while (tempEntry != None and tempEntry.nodeType == dom.Node.TEXT_NODE):
            tempEntry = tempEntry.nextSibling
        while tempEntry != None:
            try:
                cas = str(
                    (tempEntry.getElementsByTagName("computeralgebrasystem")[0]
                     ).firstChild.data).strip()
                pi = str((tempEntry.getElementsByTagName("probleminstance")[0]
                          ).firstChild.data).strip()
            except:
                raise IOError(
                    "The entries in the list of erroneous computations were not valid."
                )
            result.setRUNNING([pi, cas])
            result.setERROR([pi, cas])
            tempEntry = tempEntry.nextSibling
            while (tempEntry != None
                   and tempEntry.nodeType == dom.Node.TEXT_NODE):
                tempEntry = tempEntry.nextSibling
        return result