Exemplo n.º 1
0
    def setUp(self):
        """
        doc -- <section foo> -- <section subfoo>
                        \
                         -- <section bar> -- <section subbar>

        """
        doc = Document("author")

        foo = Section("foo", "footype")
        doc.append(foo)
        foo.append(Property("strprop", "somestring"))
        foo.append(Property("txtprop", "some\ntext"))

        subfoo = Section("subfoo", "footype")
        foo.append(subfoo)
        subfoo.append(Property("strprop", "somestring"))
        subfoo.append(Property("txtprop", "some\ntext"))

        bar = Section("bar", "bartype")
        foo.append(bar)
        bar.append(Property("strprop", "otherstring"))
        bar.append(Property("txtprop", "other\ntext"))

        subbar = Section("subbar", "bartype")
        bar.append(subbar)
        subbar.append(Property("strprop", "otherstring"))
        subbar.append(Property("txtprop", "other\ntext"))

        self.doc = doc
Exemplo n.º 2
0
    def setUp(self):
        """
        doc -- <section foo> -- <section subfoo>
                        \
                         -- <section bar> -- <section subbar>

        """
        doc = Document("author")

        foo = Section("foo", "footype")
        doc.append(foo)
        foo.append(Property("strprop", "somestring"))
        foo.append(Property("txtprop", "some\ntext"))

        subfoo = Section("subfoo", "footype")
        foo.append(subfoo)
        subfoo.append(Property("strprop", "somestring"))
        subfoo.append(Property("txtprop", "some\ntext"))

        bar = Section("bar", "bartype")
        foo.append(bar)
        bar.append(Property("strprop", "otherstring"))
        bar.append(Property("txtprop", "other\ntext"))

        subbar = Section("subbar", "bartype")
        bar.append(subbar)
        subbar.append(Property("strprop", "otherstring"))
        subbar.append(Property("txtprop", "other\ntext"))

        self.doc = doc
    def setUp(self):
        """
        doc -- <section sec_main> -- <section sub_main>
                        \
                         -- <section sec_branch> -- <section sub_branch>
        """
        doc = Document("author")

        sec_main = Section("sec_main", "maintype")
        doc.append(sec_main)
        sec_main.append(Property("strprop", "somestring"))
        sec_main.append(Property("txtprop", "some\ntext"))

        sub_main = Section("sub_main", "maintype")
        sec_main.append(sub_main)
        sub_main.append(Property("strprop", "somestring"))
        sub_main.append(Property("txtprop", "some\ntext"))

        sec_branch = Section("sec_branch", "branchtype")
        sec_main.append(sec_branch)
        sec_branch.append(Property("strprop", "otherstring"))
        sec_branch.append(Property("txtprop", "other\ntext"))

        sub_branch = Section("sub_branch", "branchtype")
        sec_branch.append(sub_branch)
        sub_branch.append(Property("strprop", "otherstring"))
        sub_branch.append(Property("txtprop", "other\ntext"))

        self.doc = doc
Exemplo n.º 4
0
    def test_read_write(self):
        doc = Document("author")
        sec = Section("name", "type")
        doc.append(sec)
        sec.append(Property("strprop", "somestring"))
        sec.append(Property("txtprop", "some\ntext"))
        sec.append(Property("intprop", 200))
        sec.append(Property("floatprop", 2.00))
        sec.append(Property("datetimeprop", dt.now()))
        sec.append(Property("dateprop", dt.now().date()))
        sec.append(Property("timeprop", dt.now().time()))
        sec.append(Property("boolprop", True))
        if sys.version_info < (3, 0):
            str_doc = unicode(XMLWriter(doc))
        else:
            str_doc = str(XMLWriter(doc))
        new_doc = XMLReader().fromString(str_doc)
        new_sec = new_doc.sections[0]

        p = new_sec.properties["strprop"]
        assert (p.dtype == "string")
        if sys.version_info < (3, 0):
            assert (type(p.value[0]) == unicode)
        else:
            assert (type(p.value[0]) == str)

        p = new_sec.properties["txtprop"]
        assert (p.dtype == "text")
        if sys.version_info < (3, 0):
            assert (type(p.value[0]) == unicode)
        else:
            assert (type(p.value[0]) == str)

        p = new_sec.properties["intprop"]
        assert (p.dtype == "int")
        assert (type(p.value[0]) == int)

        p = new_sec.properties["floatprop"]
        assert (p.dtype == "float")
        assert (type(p.value[0]) == float)

        p = new_sec.properties["datetimeprop"]
        assert (p.dtype == "datetime")
        assert (type(p.value[0]) == dt)

        p = new_sec.properties["dateprop"]
        assert (p.dtype == "date")
        assert (type(p.value[0]) == date)

        p = new_sec.properties["timeprop"]
        assert (p.dtype == "time")
        assert (type(p.value[0]) == time)

        p = new_sec.properties["boolprop"]
        assert (p.dtype == "boolean")
        assert (type(p.value[0]) == bool)
Exemplo n.º 5
0
    def test_read_write(self):
        doc = Document("author")
        sec = Section("name", "type")
        doc.append(sec)
        sec.append(Property("strprop", "somestring"))
        sec.append(Property("txtprop", "some\ntext"))
        sec.append(Property("intprop", 200))
        sec.append(Property("floatprop", 2.00))
        sec.append(Property("datetimeprop", dt.now()))
        sec.append(Property("dateprop", dt.now().date()))
        sec.append(Property("timeprop", dt.now().time()))
        sec.append(Property("boolprop", True))

        str_doc = unicode(XMLWriter(doc))
        new_doc = XMLReader().fromString(str_doc)
        new_sec = new_doc.sections[0]

        v = new_sec.properties["strprop"].value
        assert(v.dtype == "string")
        assert(type(v.data) == unicode)

        v = new_sec.properties["txtprop"].value
        assert(v.dtype == "text")
        assert(type(v.data) == unicode)

        v = new_sec.properties["intprop"].value
        assert(v.dtype == "int")
        assert(type(v.data) == int)

        v = new_sec.properties["floatprop"].value
        assert(v.dtype == "float")
        assert(type(v.data) == float)

        v = new_sec.properties["datetimeprop"].value
        assert(v.dtype == "datetime")
        assert(type(v.data) == dt)

        v = new_sec.properties["dateprop"].value
        assert(v.dtype == "date")
        assert(type(v.data) == date)

        v = new_sec.properties["timeprop"].value
        assert(v.dtype == "time")
        assert(type(v.data) == time)

        v = new_sec.properties["boolprop"].value
        assert(v.dtype == "boolean")
        assert(type(v.data) == bool)
Exemplo n.º 6
0
    def test_read_write(self):
        doc = Document("author")
        sec = Section("name", "type")
        doc.append(sec)
        sec.append(Property("strprop", "somestring"))
        sec.append(Property("txtprop", "some\ntext"))
        sec.append(Property("intprop", 200))
        sec.append(Property("floatprop", 2.00))
        sec.append(Property("datetimeprop", dt.now()))
        sec.append(Property("dateprop", dt.now().date()))
        sec.append(Property("timeprop", dt.now().time()))
        sec.append(Property("boolprop", True))

        str_doc = unicode(XMLWriter(doc))
        new_doc = XMLReader().fromString(str_doc)
        new_sec = new_doc.sections[0]

        v = new_sec.properties["strprop"].value
        assert (v.dtype == "string")
        assert (type(v.data) == unicode)

        v = new_sec.properties["txtprop"].value
        assert (v.dtype == "text")
        assert (type(v.data) == unicode)

        v = new_sec.properties["intprop"].value
        assert (v.dtype == "int")
        assert (type(v.data) == int)

        v = new_sec.properties["floatprop"].value
        assert (v.dtype == "float")
        assert (type(v.data) == float)

        v = new_sec.properties["datetimeprop"].value
        assert (v.dtype == "datetime")
        assert (type(v.data) == dt)

        v = new_sec.properties["dateprop"].value
        assert (v.dtype == "date")
        assert (type(v.data) == date)

        v = new_sec.properties["timeprop"].value
        assert (v.dtype == "time")
        assert (type(v.data) == time)

        v = new_sec.properties["boolprop"].value
        assert (v.dtype == "boolean")
        assert (type(v.data) == bool)
Exemplo n.º 7
0
    def test_append(self):
        doc = Document()
        self.assertListEqual(doc.sections, [])

        # Test append Section
        sec = Section(name="sec_one")
        doc.append(sec)
        self.assertEqual(len(doc.sections), 1)
        self.assertEqual(sec.parent, doc)

        # Test fail on Section list or tuple append
        with self.assertRaises(ValueError):
            doc.append([Section(name="sec_two"), Section(name="sec_three")])
        with self.assertRaises(ValueError):
            doc.append((Section(name="sec_two"), Section(name="sec_three")))
        self.assertEqual(len(doc.sections), 1)

        # Test fail on unsupported value
        with self.assertRaises(ValueError):
            doc.append(Document())
        with self.assertRaises(ValueError):
            doc.append("Section")
        with self.assertRaises(ValueError):
            doc.append(Property(name="prop"))

        # Test fail on same name entities
        with self.assertRaises(KeyError):
            doc.append(Section(name="sec_one"))
        self.assertEqual(len(doc.sections), 1)
Exemplo n.º 8
0
    def test_append(self):
        doc = Document()
        self.assertListEqual(doc.sections, [])

        # Test append Section
        sec = Section(name="sec_one")
        doc.append(sec)
        self.assertEqual(len(doc.sections), 1)
        self.assertEqual(sec.parent, doc)

        # Test fail on Section list or tuple append
        with self.assertRaises(ValueError):
            doc.append([Section(name="sec_two"), Section(name="sec_three")])
        with self.assertRaises(ValueError):
            doc.append((Section(name="sec_two"), Section(name="sec_three")))
        self.assertEqual(len(doc.sections), 1)

        # Test fail on unsupported value
        with self.assertRaises(ValueError):
            doc.append(Document())
        with self.assertRaises(ValueError):
            doc.append("Section")
        with self.assertRaises(ValueError):
            doc.append(Property(name="prop"))

        # Test fail on same name entities
        with self.assertRaises(KeyError):
            doc.append(Section(name="sec_one"))
        self.assertEqual(len(doc.sections), 1)