lxml.tests.test_builder

Package lxml :: Package tests :: Module test_builder |
[hide private]
[frames] | no frames]

# Source Code for Module lxml.tests.test_builder

     1  # -*- coding: utf-8 -*-
     2
     3  """
     4  Tests that ElementMaker works properly.
     5  """
     6
     7  from __future__ import absolute_import
     8
     9  import unittest
    10
    11  from lxml import etree
    12  from lxml.builder import E
    13
    14  from .common_imports import HelperTestCase, _bytes
    15
    16
    17 -class BuilderTestCase(HelperTestCase):
    18      etree = etree
    19
    20 -    def test_build_from_xpath_result(self):
    21          class StringSubclass(str): pass
    22          wrapped = E.b(StringSubclass('Hello'))
    23          self.assertEqual(_bytes('<b>Hello</b>'), etree.tostring(wrapped))
    24
    25 -    def test_unknown_type_raises(self):
    26          class UnknownType(object):
    27              pass
    28          self.assertRaises(TypeError, E.b, UnknownType())
    29
    30 -    def test_cdata(self):
    31          wrapped = E.b(etree.CDATA('Hello'))
    32          self.assertEqual(_bytes('<b><![CDATA[Hello]]></b>'), etree.tostring(wrapped))
    33
    34 -    def test_cdata_solo(self):
    35          self.assertRaises(ValueError, E.b, 'Hello', etree.CDATA('World'))
    36
    37
    38 -def test_suite():
    39      suite = unittest.TestSuite()
    40      suite.addTests([unittest.makeSuite(BuilderTestCase)])
    41      return suite
    42
    43  if __name__ == '__main__':
    44      print('to test use test.py %s' % __file__)
    45