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  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) # needed for Py3
    15
    16  from common_imports import HelperTestCase, BytesIO, _bytes
    17
    18 -class BuilderTestCase(HelperTestCase):
    19      etree = etree
    20
    21 -    def test_build_from_xpath_result(self):
    22          class StringSubclass(str): pass
    23          wrapped = E.b(StringSubclass('Hello'))
    24          self.assertEqual(_bytes('<b>Hello</b>'), etree.tostring(wrapped))
    25
    26 -    def test_unknown_type_raises(self):
    27          class UnknownType(object):
    28              pass
    29          self.assertRaises(TypeError, E.b, UnknownType())
    30
    31
    32 -def test_suite():
    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