| 1 | from genshi.core import Namespace |
|---|
| 2 | from genshi.builder import ElementFactory |
|---|
| 3 | ns1 = Namespace("http://example.com/test1") |
|---|
| 4 | ns2 = Namespace("http://example.com/test2") |
|---|
| 5 | ef1 = ElementFactory(ns1) |
|---|
| 6 | ef2 = ElementFactory(ns2) |
|---|
| 7 | |
|---|
| 8 | class 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 | |
|---|