def test_5nested_elements(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '5nested_elements.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(generator.to_string(),
                      '<note><to /><from /><heading /><body /></note>')
Esempio n. 2
0
 def test_complex_elements(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / 'complex_elements.dtd')
     self.assertEqual(len(parser.elements["Course_Catalog"].sub_elements),
                      1)
     self.assertEqual(len(parser.elements["Department"].sub_elements), 3)
     self.assertEqual(len(parser.elements["game"].sub_elements), 2)
Esempio n. 3
0
    def test_nested_child_elements(self):
        parser = DTDParser()
        parser.parse_file(self.dataPath / 'nested_child_elements.dtd')
        self.assertEqual(len(parser.elements["D"].sub_elements), 2)
        self.assertEqual(parser.elements["D"].element_name, "")
        self.assertEqual(parser.elements["D"].occurrences,
                         DTDElementCount.OneOrMore)

        self.assertEqual(parser.elements["D"].sub_elements[0].element_name,
                         "A")
        self.assertEqual(parser.elements["D"].sub_elements[0].occurrences,
                         DTDElementCount.ZeroOrOne)
        self.assertEqual(parser.elements["D"].sub_elements[0].sub_elements, [])

        self.assertEqual(
            len(parser.elements["D"].sub_elements[1].sub_elements), 2)
        self.assertEqual(parser.elements["D"].sub_elements[1].occurrences,
                         DTDElementCount.ZeroOrMore)
        self.assertEqual(parser.elements["D"].sub_elements[1].element_name, "")

        self.assertEqual(
            parser.elements["D"].sub_elements[1].sub_elements[0].element_name,
            "B")
        self.assertEqual(
            parser.elements["D"].sub_elements[1].sub_elements[0].occurrences,
            DTDElementCount.OneOrMore)
Esempio n. 4
0
    def test_1complex_element(self):
        parser = DTDParser()
        parser.parse_file(self.dataPath / '1complex_element.dtd')
        self.assertEqual(len(parser.elements["Department"].sub_elements), 3)
        self.assertEqual(parser.elements["Department"].element_name, "")

        self.assertEqual(
            parser.elements["Department"].sub_elements[0].element_name,
            "Title")
        self.assertEqual(
            parser.elements["Department"].sub_elements[0].occurrences,
            DTDElementCount.OnlyOne)
        self.assertEqual(
            parser.elements["Department"].sub_elements[0].sub_elements, [])

        self.assertEqual(
            parser.elements["Department"].sub_elements[1].element_name,
            "Course")
        self.assertEqual(
            parser.elements["Department"].sub_elements[1].occurrences,
            DTDElementCount.OneOrMore)
        self.assertEqual(
            parser.elements["Department"].sub_elements[1].sub_elements, [])

        self.assertEqual(
            parser.elements["Department"].sub_elements[2].element_name,
            "Lecturer")
        self.assertEqual(
            parser.elements["Department"].sub_elements[2].occurrences,
            DTDElementCount.ZeroOrOne)
        self.assertEqual(
            parser.elements["Department"].sub_elements[2].sub_elements, [])
 def test_1element(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(generator.to_string(), '<note />')
     self.assertEqual(generator.get_xml().get_root().tag, 'note')
    def test_9elements_3attributes(self):
        parser = DTDParser()
        parser.parse_file(self.dataPath / '9elements_3attributes.dtd')
        self.assertEqual(len(parser.elements.keys()), 9)
        self.assertEqual(count_attributes(parser.attributes), 3)

        self.assertEqual(parser.attributes["game"][0].value_type,
                         DTDAttributeValueType.REQUIRED)
        self.assertEqual(len(parser.attributes["score"]), 2)
Esempio n. 7
0
 def test_1element(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element.dtd')
     self.assertEqual(len(parser.elements["note"].sub_elements), 1)
     self.assertEqual(parser.elements["note"].element_name, "")
     self.assertEqual(parser.elements["note"].sub_elements[0].element_name,
                      "#PCDATA")
     self.assertEqual(parser.elements["note"].sub_elements[0].sub_elements,
                      [])
 def test_1element_6attributes(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element_6attributes.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(
         generator.to_string(),
         '<square width="0" number="" fax="" company="Microsoft" type="cash" '
         'title="Mr or Mrs" />')
 def test_9elements_3attributes(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '9elements_3attributes.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(
         generator.to_string(),
         '<games><game score=""><home-team /><ex-team /><scores><score time="" '
         'type=""><player /></score></scores><yellows><player '
         '/></yellows><reds><player /></reds></game></games>')
 def test_11elements_6attributes(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '11elements_6attributes.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(
         generator.to_string(),
         '<Course_Catalog Year="2017-2018"><Department Code=""><Title '
         '/><Course Number=""><Title /><Description><Courseref Number="" '
         '/></Description></Course><Lecturer InstrID=""><First_Name '
         '/><Middle_Initial /><Last_Name '
         '/></Lecturer></Department></Course_Catalog>')
    def test_1element_1attribute(self):
        parser = DTDParser()
        parser.parse_file(self.dataPath / '1element_1attribute.dtd')
        self.assertEqual(len(parser.elements), 1)
        self.assertEqual(count_attributes(parser.attributes), 1)

        self.assertEqual(parser.attributes["square"][0].attribute_name,
                         "width")
        self.assertEqual(parser.attributes["square"][0].value, "0")
        self.assertEqual(parser.attributes["square"][0].attribute_type,
                         DTDAttributeType.CDATA)
        self.assertEqual(parser.attributes["square"][0].value_type,
                         DTDAttributeValueType.VALUE)
 def test_14elements_2attributes(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '14elements_2attributes.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(
         generator.to_string(),
         '<Course_Catalog><Department Code=""><Title '
         '/><Chair><Professor><First_Name /><Middle_Initial /><Last_Name '
         '/></Professor></Chair><Course CourseNumber=""><Title /><Description '
         '/><Instructors><Lecturer><First_Name /><Middle_Initial /><Last_Name '
         '/></Lecturer><Professor><First_Name /><Middle_Initial /><Last_Name '
         '/></Professor></Instructors><Prerequisites><Prereq '
         '/></Prerequisites></Course></Department></Course_Catalog>')
 def test_9elements_3attributes(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '9elements_3attributes.dtd')
     self.assertEqual(parser.get_root(), "games")
 def test_2nested_elements(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '2nested_elements.dtd')
     self.assertEqual(parser.get_root(), "note")
Esempio n. 15
0
 def test_non_dtd_tags(self):
     parser = DTDParser()
     self.assertRaises(ValueError, parser.parse_file,
                       self.dataPath / 'invalid_token.dtd')
Esempio n. 16
0
 def test_invalid_element_children(self):
     parser = DTDParser()
     self.assertRaises(ValueError, parser.parse_file,
                       self.dataPath / 'invalid_element_children.dtd')
 def test_nested_child_elements(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / 'nested_child_elements.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(generator.to_string(), '<D><A /><B /><C /></D>')
 def test_5nested_elements(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '5nested_elements.dtd')
     self.assertEqual(len(parser._tokens), 5)
Esempio n. 19
0
 def test_file_not_found(self):
     parser = DTDParser()
     self.assertRaises(FileNotFoundError, parser.parse_file, self.dataPath / '.file_does_not_exist_gibberish.dtd.')
 def test_14elements_2attributes(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '14elements_2attributes.dtd')
     self.assertEqual(parser.get_root(), "Course_Catalog")
Esempio n. 21
0
 def test_1element(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element.dtd')
     self.assertEqual(parser._content.strip(), "<!ELEMENT note (#PCDATA)>")
Esempio n. 22
0
 def test_2nested_elements(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '2nested_elements.dtd')
     self.assertEqual(parser._content.strip(), "<!ELEMENT note (heading)>\n<!ELEMENT heading (#PCDATA)>")
Esempio n. 23
0
 def test_1element_1attribute(self):
     parser = DTDParser()
     parser.parse_string(
         '<!ELEMENT square EMPTY><!ATTLIST square width CDATA "0">')
     self.assertEqual(len(parser._tokens), 2)
Esempio n. 24
0
 def __init__(self, parser: DTDParser):
     self._parser = parser
     self._root_name = parser.get_root()
     self._xml_document = XMLDocument()
Esempio n. 25
0
 def test_no_root(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / 'no_root.dtd')
     self.assertRaises(ValueError, parser.get_root)
 def test_1element(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element.dtd')
     self.assertEqual(len(parser._tokens), 1)
 def test_1element(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element.dtd')
     self.assertEqual(parser.get_root(), "note")
Esempio n. 28
0
 def test_1element_1attribute(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element_1attribute.dtd')
     self.assertEqual(parser._content.strip(), "<!ELEMENT square EMPTY>\n<!ATTLIST square width CDATA \"0\">")
Esempio n. 29
0
 def test_1element(self):
     parser = DTDParser()
     parser.parse_string('<!ELEMENT note (#PCDATA)>')
     self.assertEqual(len(parser._tokens), 1)
 def test_1element_1attribute(self):
     parser = DTDParser()
     parser.parse_file(self.dataPath / '1element_1attribute.dtd')
     generator = XMLGenerator(parser)
     generator.generate_xml()
     self.assertEqual(generator.to_string(), '<square width="0" />')