Example #1
0
 def test_predicate_associates_with_last_step(self):
     "Test a predicate that finds the first child section of all nodes."
     path = Docpath([
         DocpathStep(Axis('root'), 'node'),
         DocpathStep(Axis('descendant_or_self'), 'node'),
         DocpathStep(Axis('child'), 'section'),
         Predicate('1')
     ])
     self.assertEqual(
         [' '.join(n['names']) for n, _ in path.traverse(self.node)],
         ['c', 'f', 'g', 'j', 'l', 'q', 'u'])
Example #2
0
 def test_predicate_not_element(self):
     "Test a predicate that find nodes that do not match."
     path = Docpath([
         DocpathStep(Axis('descendant_or_self'), 'node'),
         Predicate('name() != "section"')
     ])
     self.assertEqual(
         [n[0].__class__.__name__ for n in path.traverse(self.node)], [
             'title', 'Text', 'title', 'Text', 'title', 'Text', 'title',
             'Text', 'title', 'Text', 'title', 'Text', 'title', 'Text',
             'title', 'Text', 'title', 'Text', 'title', 'Text'
         ])
Example #3
0
 def test_docpath_creation_step_or(self):
     "Test docpath creation from or steps."
     path = Docpath((
         DocpathStep(Axis('root'), 'node'),
         DocpathStep(Axis('child'), 'section')))
     self.assertEqual(str(path), '(root::node|child::section)')
Example #4
0
 def test_docpath_creation_steps(self):
     "Test docpath creation from steps."
     path = Docpath([
         DocpathStep(Axis('root'), 'node'),
         DocpathStep(Axis('child'), 'section')])
     self.assertEqual(str(path), '/child::section')
Example #5
0
 def test_docpath_creation(self):
     "Test docpath creation."
     path = Docpath(DocpathStep(Axis('child'), 'section'))
     self.assertEqual(str(path), 'child::section')
Example #6
0
 def assertPredicateRaises(self, axis, predicates, exception):
     path = Docpath([DocpathStep(axis, 'section')] + predicates)
     with self.assertRaises(exception):
         list(path.traverse(self.node))
Example #7
0
 def assertPredicate(self, axis, predicates, matches):
     path = Docpath([DocpathStep(axis, 'section')] + predicates)
     names = [', '.join(n['names']) for n, a in path.traverse(self.node)]
     self.assertEqual(names, matches)