示例#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'])