blob: b3a31488d6b2631f1ade69fb7daf5609e9477d0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# -*- coding: utf-8 -*-
import unittest
"""
Tests that ElementMaker works properly.
"""
import sys, os.path
from lxml import etree
from lxml.builder import E
try:
import cStringIO
StringIO = cStringIO.StringIO
except ImportError:
from io import StringIO
this_dir = os.path.dirname(__file__)
if this_dir not in sys.path:
sys.path.insert(0, this_dir) # needed for Py3
from common_imports import HelperTestCase
class BuilderTestCase(HelperTestCase):
etree = etree
def test_build_from_xpath_result(self):
elem = etree.parse(StringIO('<root><node>text</node></root>'))
wrapped = E.b(elem.xpath('string(node)'))
self.assertEquals(b'<b>text</b>', etree.tostring(wrapped))
def test_suite():
suite = unittest.TestSuite()
suite.addTests([unittest.makeSuite(BuilderTestCase)])
return suite
if __name__ == '__main__':
print('to test use test.py %s' % __file__)
|