Example #1
0
    def test_get_merged_equivalent(self):
        sec = Section(name="parent")
        mersec = Section(name="merged_section")
        merprop_other = Property(name="other_prop", value="other")
        merprop = Property(name="prop", value=[1, 2, 3])

        # Check None on unset parent.
        prop = Property(name="prop")
        self.assertIsNone(prop.get_merged_equivalent())

        # Check None on parent without merged Section.
        prop.parent = sec
        self.assertIsNone(prop.get_merged_equivalent())

        # Check None on parent with merged Section but no attached Property.
        sec.merge(mersec)
        self.assertIsNone(prop.get_merged_equivalent())

        # Check None on parent with merged Section and unequal Property.
        merprop_other.parent = mersec
        self.assertIsNone(prop.get_merged_equivalent())

        # Check receiving merged equivalent Property.
        merprop.parent = mersec
        self.assertIsNotNone(prop.get_merged_equivalent())
        self.assertEqual(prop.get_merged_equivalent(), merprop)
Example #2
0
    def test_get_merged_equivalent(self):
        sec = Section(name="parent")
        mersec = Section(name="merged_section")
        merprop_other = Property(name="other_prop", value="other")
        merprop = Property(name="prop", value=[1, 2, 3])

        # Check None on unset parent.
        prop = Property(name="prop")
        self.assertIsNone(prop.get_merged_equivalent())

        # Check None on parent without merged Section.
        prop.parent = sec
        self.assertIsNone(prop.get_merged_equivalent())

        # Check None on parent with merged Section but no attached Property.
        sec.merge(mersec)
        self.assertIsNone(prop.get_merged_equivalent())

        # Check None on parent with merged Section and unequal Property.
        merprop_other.parent = mersec
        self.assertIsNone(prop.get_merged_equivalent())

        # Check receiving merged equivalent Property.
        merprop.parent = mersec
        self.assertIsNotNone(prop.get_merged_equivalent())
        self.assertEqual(prop.get_merged_equivalent(), merprop)
Example #3
0
    def test_contains(self):
        sec = Section(name="root")

        subsec = Section(name="subsec", type="test")
        prop = Property(name="prop")

        # Test not contains on empty child-lists.
        self.assertIsNone(sec.contains(subsec))
        self.assertIsNone(sec.contains(prop))

        # Test contains of Section and Property
        subsec.parent = sec
        simisec = Section(name="subsec", type="test")
        self.assertEqual(sec.contains(simisec).name, subsec.name)

        prop.parent = sec
        simiprop = Property(name="prop")
        self.assertEqual(sec.contains(simiprop).name, prop.name)

        # Test not contains on mismatching Section name/type and Property name
        self.assertIsNone(sec.contains(Section(name="subsec", type="typetest")))
        self.assertIsNone(sec.contains(Section(name="typesec", type="test")))
        self.assertIsNone(sec.contains(Property(name="prop_two")))

        # Test fail on non-Section/Property objects
        with self.assertRaises(ValueError):
            sec.contains(Document())

        with self.assertRaises(ValueError):
            sec.contains("some info")
Example #4
0
    def test_get_path(self):
        doc = Document()
        sec = Section(name="parent", parent=doc)

        # Check root path for a detached Property.
        prop = Property(name="prop")
        self.assertEqual("/", prop.get_path())

        # Check absolute path of Property in a Document.
        prop.parent = sec
        self.assertEqual("/%s:%s" % (sec.name, prop.name), prop.get_path())
Example #5
0
    def test_get_path(self):
        doc = Document()
        sec = Section(name="parent", parent=doc)

        # Check root path for a detached Property.
        prop = Property(name="prop")
        self.assertEqual("/", prop.get_path())

        # Check absolute path of Property in a Document.
        prop.parent = sec
        self.assertEqual("/%s:%s" % (sec.name, prop.name), prop.get_path())
Example #6
0
    def test_parent(self):
        p = Property("property_section", parent=Section("S"))
        self.assertIsInstance(p.parent, BaseSection)
        self.assertEqual(len(p.parent._props), 1)
        """ Test if child is removed from _props of a parent after assigning
            a new parent to the child """
        prop_parent = p.parent
        p.parent = Section("S1")
        self.assertEqual(len(prop_parent._props), 0)
        self.assertIsInstance(p.parent, BaseSection)
        self.assertIsInstance(p.parent._props[0], BaseProperty)

        prop_parent = p.parent
        p.parent = None
        self.assertIsNone(p.parent)
        self.assertEqual(len(prop_parent._props), 0)

        with self.assertRaises(ValueError):
            Property("property_prop", parent=Property("P"))
        with self.assertRaises(ValueError):
            Property("property_doc", parent=Document())
Example #7
0
    def test_parent(self):
        p = Property("property_section", parent=Section("S"))
        self.assertIsInstance(p.parent, BaseSection)
        self.assertEqual(len(p.parent._props), 1)

        """ Test if child is removed from _props of a parent after assigning
            a new parent to the child """
        prop_parent = p.parent
        p.parent = Section("S1")
        self.assertEqual(len(prop_parent._props), 0)
        self.assertIsInstance(p.parent, BaseSection)
        self.assertIsInstance(p.parent._props[0], BaseProperty)

        prop_parent = p.parent
        p.parent = None
        self.assertIsNone(p.parent)
        self.assertEqual(len(prop_parent._props), 0)

        with self.assertRaises(ValueError):
            Property("property_prop", parent=Property("P"))
        with self.assertRaises(ValueError):
            Property("property_doc", parent=Document())
Example #8
0
    def test_clone(self):
        sec = Section(name="parent")

        # Check different id.
        prop = Property(name="original")
        clone_prop = prop.clone()
        self.assertNotEqual(prop.id, clone_prop.id)

        # Check parent removal in clone.
        prop.parent = sec
        clone_prop = prop.clone()
        self.assertIsNotNone(prop.parent)
        self.assertIsNone(clone_prop.parent)

        # Check keep_id
        prop = Property(name="keepid")
        clone_prop = prop.clone(True)
        self.assertEqual(prop.id, clone_prop.id)
Example #9
0
    def test_clone(self):
        sec = Section(name="parent")

        # Check different id.
        prop = Property(name="original")
        clone_prop = prop.clone()
        self.assertNotEqual(prop.id, clone_prop.id)

        # Check parent removal in clone.
        prop.parent = sec
        clone_prop = prop.clone()
        self.assertIsNotNone(prop.parent)
        self.assertIsNone(clone_prop.parent)

        # Check keep_id
        prop = Property(name="keepid")
        clone_prop = prop.clone(True)
        self.assertEqual(prop.id, clone_prop.id)