Пример #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)
Пример #2
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'])
Пример #3
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'
         ])
Пример #4
0
 def test_predicate_forward_axis(self):
     "Test a predicate that uses a forward axis."
     self.assertPredicate(Axis('following_sibling'), [Predicate('1')],
                          ['s'])
Пример #5
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'])
Пример #6
0
 def test_predicate_node_value(self):
     "Test a predicate that tests a node's value."
     self.assertPredicate(Axis('child'), [Predicate('./section == "Q"')],
                          ['p'])
Пример #7
0
 def test_predicate_node_exists(self):
     "Test a predicate that tests whether a node exists."
     self.assertPredicate(Axis('child'), [Predicate('./section')],
                          ['k', 'p'])
Пример #8
0
 def test_predicate_attribute_value(self):
     "Test a predicate that tests an attribute's value."
     self.assertPredicate(Axis('child'), [Predicate('@names == "n"')],
                          ['n'])
Пример #9
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'])
Пример #10
0
 def test_predicate_number(self):
     "Test a predicate that only contains a number."
     self.assertPredicate(Axis('child'), [Predicate('1')], ['j'])
Пример #11
0
 def test_predicate_relational(self):
     "Test a predicate that contains a relational expression."
     self.assertPredicate(Axis('child'), [Predicate('position() > 2')],
                          ['n', 'o', 'p'])
Пример #12
0
 def test_predicate_equality(self):
     "Test a predicate that contains an equality expression."
     self.assertPredicate(Axis('child'), [Predicate('position() == 2')],
                          ['k'])
Пример #13
0
 def test_predicate_false(self):
     "Test a predicate that is always false."
     self.assertPredicate(Axis('child'), [Predicate('False')], [])
Пример #14
0
 def test_predicate_true(self):
     "Test a predicate that is always true."
     self.assertPredicate(Axis('child'), [Predicate('True')],
                          ['j', 'k', 'n', 'o', 'p'])
Пример #15
0
 def test_predicate_reverse_axis(self):
     "Test a predicate that uses a reverse axis."
     self.assertPredicate(Axis('preceding_sibling'), [Predicate('1')],
                          ['h'])
Пример #16
0
 def test_predicate_number_expression(self):
     "Test a predicate that evaluates to a number."
     self.assertPredicate(Axis('child'), [Predicate('last()')], ['p'])
Пример #17
0
 def test_predicate_double_number(self):
     "Test multiple predicates that select nodes by number."
     self.assertPredicate(Axis('child'),
                          [Predicate('4'), Predicate('1')], ['o'])
Пример #18
0
 def test_predicate_double_number_all_filtered_out(self):
     "Test multiple predicates that select no nodes."
     self.assertPredicate(Axis('child'),
                          [Predicate('1'), Predicate('4')], [])