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

Source Code for Module lxml.tests.test_elementpath

 1  # -*- coding: utf-8 -*- 
 2   
 3  """ 
 4  Tests for the ElementPath implementation. 
 5  """ 
 6   
 7  from __future__ import absolute_import 
 8   
 9  import unittest 
10  from .common_imports import etree, HelperTestCase 
11   
12   
13 -class EtreeElementPathTestCase(HelperTestCase):
14 etree = etree 15 from lxml import _elementpath 16
17 - def test_cache(self):
18 self._elementpath._cache.clear() 19 el = self.etree.XML(b'<a><b><c/><c/></b></a>') 20 self.assertFalse(self._elementpath._cache) 21 22 self.assertTrue(el.findall('b/c')) 23 self.assertEqual(1, len(self._elementpath._cache)) 24 self.assertTrue(el.findall('b/c')) 25 self.assertEqual(1, len(self._elementpath._cache)) 26 self.assertFalse(el.findall('xxx')) 27 self.assertEqual(2, len(self._elementpath._cache)) 28 self.assertFalse(el.findall('xxx')) 29 self.assertEqual(2, len(self._elementpath._cache)) 30 self.assertTrue(el.findall('b/c')) 31 self.assertEqual(2, len(self._elementpath._cache))
32 33 34 #class ElementTreeElementPathTestCase(EtreeElementPathTestCase): 35 # import xml.etree.ElementTree as etree 36 # import xml.etree.ElementPath as _elementpath 37 38
39 -def test_suite():
40 suite = unittest.TestSuite() 41 suite.addTests([unittest.makeSuite(EtreeElementPathTestCase)]) 42 #suite.addTests([unittest.makeSuite(ElementTreeElementPathTestCase)]) 43 return suite
44 45 46 if __name__ == '__main__': 47 print('to test use test.py %s' % __file__) 48