1
2 import unittest
3
4 """
5 Tests that ElementMaker works properly.
6 """
7
8 import sys, os.path
9 from lxml import etree
10 from lxml.builder import E
11
12 this_dir = os.path.dirname(__file__)
13 if this_dir not in sys.path:
14 sys.path.insert(0, this_dir)
15
16 from common_imports import HelperTestCase, BytesIO, _bytes
17
19 etree = etree
20
22 class StringSubclass(str): pass
23 wrapped = E.b(StringSubclass('Hello'))
24 self.assertEquals(_bytes('<b>Hello</b>'), etree.tostring(wrapped))
25
27 class UnknownType(object):
28 pass
29 self.assertRaises(TypeError, E.b, UnknownType())
30
31
33 suite = unittest.TestSuite()
34 suite.addTests([unittest.makeSuite(BuilderTestCase)])
35 return suite
36
37 if __name__ == '__main__':
38 print('to test use test.py %s' % __file__)
39