Example #1
0
    def test_create_section(self):
        root = Document()
        self.assertEqual(len(root.sections), 0)

        name = "subsec"
        sec_type = "subtype"
        oid = "79b613eb-a256-46bf-84f6-207df465b8f7"
        subsec = root.create_section(name, sec_type, oid)

        self.assertEqual(len(root.sections), 1)
        self.assertEqual(subsec.parent, root)
        self.assertEqual(root.sections[name], subsec)
        self.assertEqual(root.sections[name].type, sec_type)
        self.assertEqual(root.sections[name].oid, oid)

        name = "othersec"
        subsec = root.create_section(name)
        self.assertEqual(len(root.sections), 2)
        self.assertEqual(subsec.parent, root)
        self.assertEqual(root.sections[name], subsec)
        self.assertEqual(root.sections[name].type, "n.s.")

        name = "subsubsec"
        subsec = root.sections[0].create_section(name)
        self.assertEqual(len(root.sections), 2)
        self.assertEqual(subsec.parent, root.sections[0])
        self.assertEqual(len(root.sections[0].sections), 1)
        self.assertEqual(root.sections[0].sections[0].name, name)
Example #2
0
    def test_create_section(self):
        root = Document()
        self.assertEqual(len(root.sections), 0)

        name = "subsec"
        type = "subtype"
        oid = "79b613eb-a256-46bf-84f6-207df465b8f7"
        subsec = root.create_section(name, type, oid)

        self.assertEqual(len(root.sections), 1)
        self.assertEqual(subsec.parent, root)
        self.assertEqual(root.sections[name], subsec)
        self.assertEqual(root.sections[name].type, type)
        self.assertEqual(root.sections[name].oid, oid)

        name = "othersec"
        subsec = root.create_section(name)
        self.assertEqual(len(root.sections), 2)
        self.assertEqual(subsec.parent, root)
        self.assertEqual(root.sections[name], subsec)
        self.assertEqual(root.sections[name].type, "undefined")

        name = "subsubsec"
        subsec = root.sections[0].create_section(name)
        self.assertEqual(len(root.sections), 2)
        self.assertEqual(subsec.parent, root.sections[0])
        self.assertEqual(len(root.sections[0].sections), 1)
        self.assertEqual(root.sections[0].sections[0].name, name)
Example #3
0
    def test_export_leaf(self):
        doc = Document()
        first = doc.create_section("first")
        second = first.create_section("second")
        third = first.create_section("third")

        name = "prop1"
        values = [1.3]
        first.create_property(name, value=values)

        name = "prop2"
        values = ["words"]
        first.create_property(name, value=values)

        name = "prop3"
        values = ["a", "b"]
        second.create_property(name, value=values)

        ex1 = first.export_leaf()
        self.assertEqual(len(ex1.sections), 1)
        self.assertEqual(len(ex1['first'].properties), 2)
        self.assertEqual(len(ex1['first'].sections), 0)

        ex2 = second.export_leaf()
        self.assertEqual(len(ex2.sections), 1)
        self.assertEqual(len(ex2['first'].properties), 2)
        self.assertEqual(len(ex2['first'].sections), 1)
        self.assertEqual(len(ex2['first']['second'].properties), 1)

        ex3 = third.export_leaf()
        self.assertEqual(len(ex3.sections), 1)
        self.assertEqual(len(ex3['first'].properties), 2)
        self.assertEqual(len(ex3['first'].sections), 1)
        self.assertEqual(len(ex3['first']['third']), 0)
Example #4
0
    def test_export_leaf(self):
        doc = Document()

        sec_a_name = "first"
        sec_b_name = "second"
        first = doc.create_section(sec_a_name)
        second = first.create_section(sec_b_name)
        _ = first.create_section("third")

        prop_aa = first.create_property("prop1", value=[1.3])
        _ = first.create_property("prop5", value=["abc"])
        prop_ba = second.create_property("prop2", value=["words"])
        _ = second.create_property("prop3", value=["a", "b"])
        _ = second.create_property("prop4", value=[3])

        export_doc = prop_aa.export_leaf()
        self.assertEqual(len(export_doc[sec_a_name].properties), 2)
        self.assertEqual(len(export_doc[sec_a_name].sections), 0)

        export_doc = prop_ba.export_leaf()
        self.assertEqual(len(export_doc.sections), 1)
        self.assertEqual(len(export_doc[sec_a_name].properties), 2)
        self.assertEqual(len(export_doc[sec_a_name].sections), 1)
        self.assertEqual(len(export_doc[sec_a_name][sec_b_name].properties), 3)