Package lxml :: Package tests :: Module test_threading
[frames] | no frames]

Source Code for Module lxml.tests.test_threading

 1  # -*- coding: utf-8 -*- 
 2   
 3  """ 
 4  Tests for thread usage in lxml.etree. 
 5  """ 
 6   
 7  import unittest, threading 
 8   
 9  from common_imports import etree, HelperTestCase 
10   
11 -class ThreadingTestCase(HelperTestCase):
12 """Threading tests""" 13 etree = etree 14
15 - def test_subtree_copy(self):
16 tostring = self.etree.tostring 17 XML = self.etree.XML 18 xml = "<root><threadtag/></root>" 19 main_root = XML("<root/>") 20 21 def run_thread(): 22 thread_root = XML(xml) 23 main_root.append(thread_root[0]) 24 del thread_root
25 26 thread = threading.Thread(target=run_thread) 27 thread.start() 28 thread.join() 29 30 self.assertEquals(xml, tostring(main_root))
31
32 -def test_suite():
33 suite = unittest.TestSuite() 34 suite.addTests([unittest.makeSuite(ThreadingTestCase)]) 35 return suite
36 37 if __name__ == '__main__': 38 print 'to test use test.py %s' % __file__ 39