Exemplo n.º 1
0
 def test_predicate_assignment_operator(self):
     "Test a predicate cannot contain an assignment operator."
     self.assertPredicateRaises(Axis('child'),
                                [Predicate('./section = "Q"')], SyntaxError)
     self.assertPredicateRaises(Axis('child'),
                                [Predicate('@attribute = "Q"')],
                                SyntaxError)
Exemplo n.º 2
0
 def test_axis_traverse_parent(self):
     "Test the parent doctree traversal."
     self.assertNameTraversal(
         Axis('parent').traverse,
         ['e'])
     self.assertNameTraversal(
         Axis('parent').traverse_backwards,
         ['e'])
Exemplo n.º 3
0
 def test_axis_traverse_preceding_sibling(self):
     "Test the preceding sibling doctree traversal."
     self.assertNameTraversal(
         Axis('preceding_sibling').traverse,
         ['h', 'f'])
     self.assertNameTraversal(
         Axis('preceding_sibling').traverse_backwards,
         ['f', 'h'])
Exemplo n.º 4
0
 def test_axis_traverse_root(self):
     "Test the root doctree traversal."
     self.assertNameTraversal(
         Axis('root').traverse,
         ['a'])
     self.assertNameTraversal(
         Axis('root').traverse_backwards,
         ['a'])
Exemplo n.º 5
0
 def test_axis_traverse_self(self):
     "Test the self doctree traversal."
     self.assertNameTraversal(
         Axis('self').traverse,
         ['i'])
     self.assertNameTraversal(
         Axis('self').traverse_backwards,
         ['i'])
Exemplo n.º 6
0
 def test_axis_traverse_ancestor(self):
     "Test the ancestor doctree traversal."
     self.assertNameTraversal(
         Axis('ancestor').traverse,
         ['e', 'a'])
     self.assertNameTraversal(
         Axis('ancestor').traverse_backwards,
         ['a', 'e'])
Exemplo n.º 7
0
 def test_axis_traverse_ancestor_or_self(self):
     "Test the ancestor or self doctree traversal."
     self.assertNameTraversal(
         Axis('ancestor_or_self').traverse,
         ['i', 'e', 'a'])
     self.assertNameTraversal(
         Axis('ancestor_or_self').traverse_backwards,
         ['a', 'e', 'i'])
Exemplo n.º 8
0
 def test_axis_traverse_child(self):
     "Test the child doctree traversal."
     self.assertNameTraversal(
         Axis('child').traverse,
         ['j', 'k', 'n', 'o', 'p'])
     self.assertNameTraversal(
         Axis('child').traverse_backwards,
         ['p', 'o', 'n', 'k', 'j'])
Exemplo n.º 9
0
 def test_axis_traverse_descendant_or_self(self):
     "Test the descendant or self doctree traversal."
     self.assertNameTraversal(
         Axis('descendant_or_self').traverse,
         ['i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r'])
     self.assertNameTraversal(
         Axis('descendant_or_self').traverse_backwards,
         ['r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i'])
Exemplo n.º 10
0
 def test_axis_traverse_following_sibling(self):
     "Test the following sibling doctree traversal."
     self.assertNameTraversal(
         Axis('following_sibling').traverse,
         ['s', 't'])
     self.assertNameTraversal(
         Axis('following_sibling').traverse_backwards,
         ['t', 's'])
Exemplo n.º 11
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'])
Exemplo n.º 12
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'
         ])
Exemplo n.º 13
0
 def test_predicate_number(self):
     "Test a predicate that only contains a number."
     self.assertPredicate(Axis('child'), [Predicate('1')], ['j'])
Exemplo n.º 14
0
 def test_predicate_number_expression(self):
     "Test a predicate that evaluates to a number."
     self.assertPredicate(Axis('child'), [Predicate('last()')], ['p'])
Exemplo n.º 15
0
 def test_axis_traverse_attribute(self):
     "Test the attribute doctree traversal."
     self.assertAttributeTraversal(
         Axis('attribute').traverse,
         set(['backrefs', 'names', 'classes', 'dupnames', 'ids']))
Exemplo n.º 16
0
 def test_axis_node_address(self):
     "Test the node address is calculated correctly."
     self.assertEqual(Axis.node_address(self.node), (1, 4, 3))
Exemplo n.º 17
0
 def test_predicate_attribute_exists(self):
     "Test a predicate that tests whether an attribute exists."
     self.assertPredicate(Axis('child'), [Predicate('@names')],
                          ['j', 'k', 'n', 'o', 'p'])
Exemplo n.º 18
0
 def test_predicate_double_number(self):
     "Test multiple predicates that select nodes by number."
     self.assertPredicate(Axis('child'),
                          [Predicate('4'), Predicate('1')], ['o'])
Exemplo n.º 19
0
 def test_predicate_attribute_value(self):
     "Test a predicate that tests an attribute's value."
     self.assertPredicate(Axis('child'), [Predicate('@names == "n"')],
                          ['n'])
Exemplo n.º 20
0
 def setUp(self):
     source = join(dirname(__file__), 'doc', 'doctree.rst')
     with open(source, 'r', encoding='utf-8') as rst:
         self.doctree = publish_doctree(rst.read())
     self.node = self.doctree.next_node(self._matches_node_i)
     self.address = Axis.node_address(self.node)
Exemplo n.º 21
0
 def test_predicate_node_value(self):
     "Test a predicate that tests a node's value."
     self.assertPredicate(Axis('child'), [Predicate('./section == "Q"')],
                          ['p'])
Exemplo n.º 22
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)
Exemplo n.º 23
0
 def test_predicate_count_nodeset(self):
     "Test a predicate that counts the amount of nodes in a path."
     self.assertPredicate(Axis('child'),
                          [Predicate('count(^//section) == 21')],
                          ['j', 'k', 'n', 'o', 'p'])
Exemplo n.º 24
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)')
Exemplo n.º 25
0
 def test_predicate_forward_axis(self):
     "Test a predicate that uses a forward axis."
     self.assertPredicate(Axis('following_sibling'), [Predicate('1')],
                          ['s'])
Exemplo n.º 26
0
 def test_docpath_creation(self):
     "Test docpath creation."
     path = Docpath(DocpathStep(Axis('child'), 'section'))
     self.assertEqual(str(path), 'child::section')
Exemplo n.º 27
0
 def test_predicate_relational(self):
     "Test a predicate that contains a relational expression."
     self.assertPredicate(Axis('child'), [Predicate('position() > 2')],
                          ['n', 'o', 'p'])
Exemplo n.º 28
0
 def test_predicate_node_exists(self):
     "Test a predicate that tests whether a node exists."
     self.assertPredicate(Axis('child'), [Predicate('./section')],
                          ['k', 'p'])
Exemplo n.º 29
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')
Exemplo n.º 30
0
 def test_predicate_reverse_axis(self):
     "Test a predicate that uses a reverse axis."
     self.assertPredicate(Axis('preceding_sibling'), [Predicate('1')],
                          ['h'])