Esempio 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)
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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'
         ])
Esempio n. 13
0
 def test_predicate_number(self):
     "Test a predicate that only contains a number."
     self.assertPredicate(Axis('child'), [Predicate('1')], ['j'])
Esempio n. 14
0
 def test_predicate_number_expression(self):
     "Test a predicate that evaluates to a number."
     self.assertPredicate(Axis('child'), [Predicate('last()')], ['p'])
Esempio 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']))
Esempio 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))
Esempio 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'])
Esempio 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'])
Esempio 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'])
Esempio 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)
Esempio 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'])
Esempio 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)
Esempio 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'])
Esempio 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)')
Esempio 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'])
Esempio n. 26
0
 def test_docpath_creation(self):
     "Test docpath creation."
     path = Docpath(DocpathStep(Axis('child'), 'section'))
     self.assertEqual(str(path), 'child::section')
Esempio 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'])
Esempio 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'])
Esempio 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')
Esempio 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'])