Beispiel #1
0
    def test_comparison(self):
        doc_auth = "author"
        doc_ver = "ver1.0"

        doc_a = Document(author=doc_auth, version=doc_ver)
        doc_b = Document(author=doc_auth, version=doc_ver)

        self.assertEqual(doc_a, doc_b)

        doc_b.author = "someone else"
        self.assertNotEqual(doc_a, doc_b)

        doc_b.author = doc_auth

        # Test section equality with subsections

        # Test equality with subsection of different entities
        # with same content and same children order
        sec_type = "sec type"
        sec_def = "an odml test section"
        sec_ref = "from over there"

        subsec_aa = Section(name="subsecA",
                            type=sec_type,
                            definition=sec_def,
                            reference=sec_ref)
        subsec_ab = Section(name="subsecB",
                            type=sec_type,
                            definition=sec_def,
                            reference=sec_ref)
        subsec_ba = Section(name="subsecA",
                            type=sec_type,
                            definition=sec_def,
                            reference=sec_ref)
        subsec_bb = Section(name="subsecB",
                            type=sec_type,
                            definition=sec_def,
                            reference=sec_ref)

        doc_a.extend([subsec_aa, subsec_ab])
        doc_b.extend([subsec_ba, subsec_bb])

        self.assertEqual(doc_a, doc_b)
        self.assertEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "newSubsecA"
        self.assertNotEqual(doc_a, doc_b)
        self.assertNotEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "subsecA"

        # Test inequality with different number of children
        doc_b.remove(doc_b.sections[1])
        self.assertNotEqual(doc_a, doc_b)
        self.assertNotEqual(doc_a.sections, doc_b.sections)

        # Test equality with subsection of different entities
        # with same content and different children order
        doc_b.remove(doc_b.sections[0])
        doc_b.extend([subsec_bb, subsec_ba])

        self.assertEqual(doc_a, doc_b)
        self.assertEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "newSubsecB"
        self.assertNotEqual(doc_a, doc_b)
        self.assertNotEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "subsecB"

        # Test section equality with properties

        # Test equality with properties of different entities
        # with same content and same children order
        prop_aa = Property(name="propA", definition="propDef")
        prop_ab = Property(name="propB", definition="propDef")
        prop_ba = Property(name="propA", definition="propDef")
        prop_bb = Property(name="propB", definition="propDef")

        doc_a.sections["subsecA"].extend([prop_aa, prop_ab])
        doc_b.sections["subsecA"].extend([prop_ba, prop_bb])

        self.assertEqual(doc_a, doc_b)

        doc_b.sections["subsecA"].properties[0].name = "newPropA"
        self.assertNotEqual(doc_a, doc_b)

        doc_b.sections["subsecA"].properties[0].name = "propA"

        # Test inequality with different number of children
        doc_b.sections["subsecA"].remove(
            doc_b.sections["subsecA"].properties[1])
        self.assertNotEqual(doc_a, doc_b)

        # Test equality with properties of different entities
        # with same content and different children order
        doc_b.sections["subsecA"].remove(
            doc_b.sections["subsecA"].properties[0])
        doc_b.sections["subsecA"].extend([prop_bb, prop_ba])

        self.assertEqual(doc_a, doc_b)

        doc_b.sections["subsecA"].properties[0].name = "newPropB"
        self.assertNotEqual(doc_a, doc_b)
Beispiel #2
0
    def test_comparison(self):
        doc_auth = "author"
        doc_ver = "ver1.0"

        doc_a = Document(author=doc_auth, version=doc_ver)
        doc_b = Document(author=doc_auth, version=doc_ver)

        self.assertEqual(doc_a, doc_b)

        doc_b.author = "someone else"
        self.assertNotEqual(doc_a, doc_b)

        doc_b.author = doc_auth

        # Test section equality with subsections

        # Test equality with subsection of different entities
        # with same content and same children order
        sec_type = "sec type"
        sec_def = "an odml test section"
        sec_ref = "from over there"

        subsec_aa = Section(name="subsecA", type=sec_type,
                            definition=sec_def, reference=sec_ref)
        subsec_ab = Section(name="subsecB", type=sec_type,
                            definition=sec_def, reference=sec_ref)
        subsec_ba = Section(name="subsecA", type=sec_type,
                            definition=sec_def, reference=sec_ref)
        subsec_bb = Section(name="subsecB", type=sec_type,
                            definition=sec_def, reference=sec_ref)

        doc_a.extend([subsec_aa, subsec_ab])
        doc_b.extend([subsec_ba, subsec_bb])

        self.assertEqual(doc_a, doc_b)
        self.assertEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "newSubsecA"
        self.assertNotEqual(doc_a, doc_b)
        self.assertNotEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "subsecA"

        # Test inequality with different number of children
        doc_b.remove(doc_b.sections[1])
        self.assertNotEqual(doc_a, doc_b)
        self.assertNotEqual(doc_a.sections, doc_b.sections)

        # Test equality with subsection of different entities
        # with same content and different children order
        doc_b.remove(doc_b.sections[0])
        doc_b.extend([subsec_bb, subsec_ba])

        self.assertEqual(doc_a, doc_b)
        self.assertEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "newSubsecB"
        self.assertNotEqual(doc_a, doc_b)
        self.assertNotEqual(doc_a.sections, doc_b.sections)

        doc_b.sections[0].name = "subsecB"

        # Test section equality with properties

        # Test equality with properties of different entities
        # with same content and same children order
        prop_aa = Property(name="propA", definition="propDef")
        prop_ab = Property(name="propB", definition="propDef")
        prop_ba = Property(name="propA", definition="propDef")
        prop_bb = Property(name="propB", definition="propDef")

        doc_a.sections["subsecA"].extend([prop_aa, prop_ab])
        doc_b.sections["subsecA"].extend([prop_ba, prop_bb])

        self.assertEqual(doc_a, doc_b)

        doc_b.sections["subsecA"].properties[0].name = "newPropA"
        self.assertNotEqual(doc_a, doc_b)

        doc_b.sections["subsecA"].properties[0].name = "propA"

        # Test inequality with different number of children
        doc_b.sections["subsecA"].remove(doc_b.sections["subsecA"].properties[1])
        self.assertNotEqual(doc_a, doc_b)

        # Test equality with properties of different entities
        # with same content and different children order
        doc_b.sections["subsecA"].remove(doc_b.sections["subsecA"].properties[0])
        doc_b.sections["subsecA"].extend([prop_bb, prop_ba])

        self.assertEqual(doc_a, doc_b)

        doc_b.sections["subsecA"].properties[0].name = "newPropB"
        self.assertNotEqual(doc_a, doc_b)
Beispiel #3
0
    def test_extend(self):
        doc = Document()
        self.assertListEqual(doc.sections, [])

        # Test extend with Section list
        doc.extend([Section(name="sec_one"), Section(name="sec_two")])
        self.assertEqual(len(doc), 2)
        self.assertEqual(len(doc.sections), 2)
        self.assertEqual(doc.sections[0].name, "sec_one")

        # Test fail on non iterable
        with self.assertRaises(TypeError):
            doc.extend(1)
        self.assertEqual(len(doc.sections), 2)

        # Test fail on non Section entry
        with self.assertRaises(ValueError):
            doc.extend([Document()])
        with self.assertRaises(ValueError):
            doc.extend([Property(name="prop")])
        with self.assertRaises(ValueError):
            doc.extend([5])
        self.assertEqual(len(doc.sections), 2)

        # Test fail on same name entities
        with self.assertRaises(KeyError):
            doc.extend([Section(name="sec_three"), Section(name="sec_one")])
        self.assertEqual(len(doc.sections), 2)
Beispiel #4
0
    def test_extend(self):
        doc = Document()
        self.assertListEqual(doc.sections, [])

        # Test extend with Section list
        doc.extend([Section(name="sec_one"), Section(name="sec_two")])
        self.assertEqual(len(doc), 2)
        self.assertEqual(len(doc.sections), 2)
        self.assertEqual(doc.sections[0].name, "sec_one")

        # Test fail on non iterable
        with self.assertRaises(TypeError):
            doc.extend(1)
        self.assertEqual(len(doc.sections), 2)

        # Test fail on non Section entry
        with self.assertRaises(ValueError):
            doc.extend([Document()])
        with self.assertRaises(ValueError):
            doc.extend([Property(name="prop")])
        with self.assertRaises(ValueError):
            doc.extend([5])
        self.assertEqual(len(doc.sections), 2)

        # Test fail on same name entities
        with self.assertRaises(KeyError):
            doc.extend([Section(name="sec_three"), Section(name="sec_one")])
        self.assertEqual(len(doc.sections), 2)