Beispiel #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'])
Beispiel #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'
         ])
Beispiel #3
0
 def assertFilterNodes(self, node_test, matches):
     step = DocpathStep(Axis('child'), node_test)
     filtered_nodes = step.filter_nodes(self.node_addresses)
     self.assertEqual(list(filtered_nodes), matches)
Beispiel #4
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)')
Beispiel #5
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')
Beispiel #6
0
 def test_docpath_creation(self):
     "Test docpath creation."
     path = Docpath(DocpathStep(Axis('child'), 'section'))
     self.assertEqual(str(path), 'child::section')
Beispiel #7
0
 def assertPredicateRaises(self, axis, predicates, exception):
     path = Docpath([DocpathStep(axis, 'section')] + predicates)
     with self.assertRaises(exception):
         list(path.traverse(self.node))
Beispiel #8
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)