From 5d458bf6c2fae32d659b29ac2697a20b781bfbd0 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Wed, 25 Aug 2010 10:52:07 -0400 Subject: Updated ElementBase._delSub and added unit tests. _delSub can now accept a path and will optionally remove any empty parent elements after deleting the target elements. --- tests/test_elementbase.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'tests') diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 2b61489a..9628ea6c 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -352,5 +352,81 @@ class TestElementBase(SleekTest): """) + def testDelSub(self): + """Test removing sub elements.""" + + class TestStanza(ElementBase): + name = "foo" + namespace = "foo" + interfaces = set(('bar', 'baz')) + + def setBar(self, value): + self._setSubText("path/to/only/bar", value); + + def getBar(self): + return self._getSubText("path/to/only/bar") + + def delBar(self): + self._delSub("path/to/only/bar") + + def setBaz(self, value): + self._setSubText("path/to/just/baz", value); + + def getBaz(self): + return self._getSubText("path/to/just/baz") + + def delBaz(self): + self._delSub("path/to/just/baz") + + stanza = TestStanza() + stanza['bar'] = 'a' + stanza['baz'] = 'b' + + self.checkStanza(TestStanza, stanza, """ + + + + + a + + + b + + + + + """) + + del stanza['bar'] + del stanza['baz'] + + self.checkStanza(TestStanza, stanza, """ + + + + + + + + + """, use_values=False) + + stanza['bar'] = 'a' + stanza['baz'] = 'b' + + stanza._delSub('path/to/only/bar', all=True) + + self.checkStanza(TestStanza, stanza, """ + + + + + b + + + + + """) + suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase) -- cgit v1.2.3