1 # -*- coding: utf-8 -*-
2 import unittest, doctest
4 # These tests check that error handling in the Pyrex code is
6 # It is likely that if there are errors, instead of failing the code
9 import sys, gc, os.path
10 from lxml import etree
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
16 from common_imports import HelperTestCase
18 class ErrorTestCase(HelperTestCase):
21 def test_bad_element(self):
22 # attrib argument of Element() should be a dictionary, so if
23 # we pass a string we should get an error.
24 self.assertRaises(TypeError, self.etree.Element, 'a', 'b')
26 def test_empty_parse(self):
27 self.assertRaises(etree.XMLSyntaxError, etree.fromstring, '')
29 def test_element_cyclic_gc_none(self):
30 # test if cyclic reference can crash etree
31 Element = self.etree.Element
34 count = sys.getrefcount(None)
36 l = [Element('name'), Element('name')]
42 self.assertEquals(sys.getrefcount(None), count)
45 suite = unittest.TestSuite()
46 suite.addTests([unittest.makeSuite(ErrorTestCase)])
49 if __name__ == '__main__':
50 print('to test use test.py %s' % __file__)