Пример #1
0
 def test_docpath_or(self):
     "Test docpaths or."
     docpath = path('/self::document|//subtitle|//section')
     self.assertEqual(
         [', '.join(n['names']) for n in docpath.findall(self.node)],
         ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w'])
Пример #2
0
 def test_parser_complex(self):
     "Test docpath creation from a complex path."
     docpath = path('//section/.././following_sibling::*')
     self.assertEqual(
         str(docpath),
         '/descendant_or_self::node/child::section/parent::node'
         '/self::node/following_sibling::element')
Пример #3
0
 def test_docpath_findall(self):
     "Test docpath findall."
     docpath = path('//section')
     self.assertEqual(
         [', '.join(n['names']) for n in docpath.findall(self.node)],
         ['c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
          'p', 'q', 'r', 's', 't', 'u', 'v', 'w'])
Пример #4
0
 def test_docpath_traverse(self):
     "Test docpath traverse."
     docpath = path('//section')
     self.assertEqual(
         [', '.join(n['names']) for n, a in docpath.traverse(self.node)],
         ['c', 'd', 'e', 'v', 'w', 'f', 'h', 'i', 's', 't', 'g', 'j', 'k',
          'n', 'o', 'p', 'l', 'm', 'q', 'r', 'u'])
Пример #5
0
 def test_parser_relative(self):
     "Test docpath creation from a relative path."
     docpath = path('section')
     self.assertEqual(str(docpath), 'child::section')
Пример #6
0
 def test_parser_or_middle(self):
     "Test docpath creation from a path containing a single predicate."
     docpath = path('node/(section|paragraph)/node')
     self.assertEqual(
         str(docpath),
         'child::node/(child::section|child::paragraph)/child::node')
Пример #7
0
 def test_parser_or(self):
     "Test docpath creation from a path containing a single predicate."
     docpath = path('section|paragraph|title')
     self.assertEqual(str(docpath),
                      '(child::section|child::paragraph|child::title)')
Пример #8
0
 def test_parser_multiple_predicates(self):
     "Test docpath creation from a path containing multiple predicates."
     docpath = path('section[@name == "n"][1]')
     self.assertEqual(str(docpath),
                      'child::section[attribute.name == "n"][1]')
Пример #9
0
 def test_parser_single_predicate(self):
     "Test docpath creation from a path containing a single predicate."
     docpath = path('section[1]')
     self.assertEqual(str(docpath), 'child::section[1]')
Пример #10
0
 def test_parser_axis(self):
     "Test docpath creation from a wildcard path."
     docpath = path('following_sibling::section')
     self.assertEqual(str(docpath), 'following_sibling::section')
Пример #11
0
 def test_parser_wildcard(self):
     "Test docpath creation from a wildcard path."
     docpath = path('*')
     self.assertEqual(str(docpath), 'child::element')
Пример #12
0
 def test_parser_parent(self):
     "Test docpath creation from a parent path."
     docpath = path('../section')
     self.assertEqual(str(docpath), 'parent::node/child::section')
Пример #13
0
 def test_parser_self(self):
     "Test docpath creation from a self path."
     docpath = path('./section')
     self.assertEqual(str(docpath), 'self::node/child::section')
Пример #14
0
 def test_parser_absolute(self):
     "Test docpath creation from an absolute path."
     docpath = path('/section')
     self.assertEqual(str(docpath), '/child::section')
Пример #15
0
 def test_docpath_find_nothing(self):
     "Test docpath find that returns None."
     docpath = path('paragraph')
     self.assertIsNone(docpath.find(self.node))
Пример #16
0
 def test_docpath_find(self):
     "Test docpath find."
     docpath = path('//section')
     self.assertEqual(
         docpath.find(self.node)['names'],
         ['c'])