Edgewall Software

Ticket #160: NamespaceFlattenerTest.py

File NamespaceFlattenerTest.py, 1.2 KB (added by ben@…, 16 years ago)
Line 
1from genshi.core import Namespace
2from genshi.builder import ElementFactory
3ns1 = Namespace("http://example.com/test1")
4ns2 = Namespace("http://example.com/test2")
5ef1 = ElementFactory(ns1)
6ef2 = ElementFactory(ns2)
7
8class NamespaceFlattenerTest(TestCase):
9    def testSingleNamespace(self):
10        elt = ef1.x(ef1.y, ef1.z)
11        self.failUnlessEqual(str(elt), '<x xmlns="http://example.com/test1"><y/><z/></x>')
12
13    def testTwoNamespaces(self):
14        elt = ef1.x(ef1.y, ef2.z)
15        self.failUnlessEqual(str(elt), '<x xmlns="http://example.com/test1"><y/><z xmlns="http://example.com/test2"/></x>')
16
17        elt = ef1.x(ef2.y, ef1.z)
18        self.failUnlessEqual(str(elt), '<x xmlns="http://example.com/test1"><y xmlns="http://example.com/test2"/><z/></x>')
19
20        elt = ef1.x(ef2.y, ef2.z)
21        self.failUnlessEqual(str(elt), '<x xmlns="http://example.com/test1"><y xmlns="http://example.com/test2"/><z xmlns="http://example.com/test2"/></x>')
22
23    def testAttributes(self):
24        elt = ef1.x(ef1.y, ef2.z)
25        elt.attrib |= [(ns2.a1, "v1")]
26        self.failUnlessEqual(str(elt), '<x ns1:a1="v1" xmlns="http://example.com/test1" xmlns:ns1="http://example.com/test2"><y/><ns1:z/></x>')
27