Exemplo n.º 1
0
 def test_checkSequenceLessClose(self):
     """
     Fail utils.checkXMLtagsSequence()
     If 2 opens and 1 close
     """
     inputList = ["<group>", "</group>", "<group>"]
     with self.assertRaises(XMLtagError):
         utils.checkXMLtagsSequence(inputList, "group")
Exemplo n.º 2
0
 def test_checkSequenceStartWithClose(self):
     """
     Fail utils.checkXMLtagsSequence()
     If close/open/close/open
     """
     inputList = ["</group>", "<group>", "</group>", "<group>"]
     with self.assertRaises(XMLtagError):
         utils.checkXMLtagsSequence(inputList, "group")
Exemplo n.º 3
0
 def test_checkSequenceNested(self):
     """
     Fail utils.checkXMLtagsSequence()
     if tags are nested (<tag><tag></tag></tag>).
     """
     inputList = ["<group>", "<group>", "</group>", "</group>"]
     with self.assertRaises(XMLtagError):
         utils.checkXMLtagsSequence(inputList, "group")
Exemplo n.º 4
0
    def importFromXML(self, xmlTaggedInput):
        """
        Import XML-tagged proof and convert to ProofPreset() object.
        xmlTaggedInput can be a filePath, a string, or a list.

        File extensions can be .xml or .txt.
        Recognized XML tags are <group> </group>

        If xmlTaggedInput is a string:
        "<group>\nUC\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n</group>"

        if xmlTaggedInput is a list:
        ["<group>", "UC", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "</group>"]

        This method performs some basic cleaning & validation,
        including ingnoring everything before first <group> tag
        and everything after last </group> tag.
        """
        xmlObj = None
        if isinstance(xmlTaggedInput, str):
            if not os.path.isfile(xmlTaggedInput):
                xmlObj = xmlTaggedInput.split("\n")

            else:
                ext = os.path.splitext(xmlTaggedInput)[1].lower()
                if ext in (".xml", ".txt"):
                    with open(xmlTaggedInput, "r") as xmlFile:
                        xmlObj = xmlFile.readlines()

        elif isinstance(xmlTaggedInput, list):
            xmlObj = copy.deepcopy(xmlTaggedInput)

        if not xmlObj:
            raise ProofPresetError("Invalid XML input")

        self._xmlGroups = utils.cleanList(xmlObj,
                                          discardBefore="<group>",
                                          discardAfter="</group>")

        if not self._xmlGroups:
            raise ProofPresetError("Imported XML object is empty")

        utils.checkForTags(self._xmlGroups, "group")
        utils.checkXMLtagsSequence(self._xmlGroups, "group")

        # Main import & fix groupNames
        self.preset["groups"] = self._makePresetGroupsFromXML()
        self._inspectAndFixGroupNames()