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'])
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')
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'])
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'])
def test_parser_relative(self): "Test docpath creation from a relative path." docpath = path('section') self.assertEqual(str(docpath), 'child::section')
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')
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)')
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]')
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]')
def test_parser_axis(self): "Test docpath creation from a wildcard path." docpath = path('following_sibling::section') self.assertEqual(str(docpath), 'following_sibling::section')
def test_parser_wildcard(self): "Test docpath creation from a wildcard path." docpath = path('*') self.assertEqual(str(docpath), 'child::element')
def test_parser_parent(self): "Test docpath creation from a parent path." docpath = path('../section') self.assertEqual(str(docpath), 'parent::node/child::section')
def test_parser_self(self): "Test docpath creation from a self path." docpath = path('./section') self.assertEqual(str(docpath), 'self::node/child::section')
def test_parser_absolute(self): "Test docpath creation from an absolute path." docpath = path('/section') self.assertEqual(str(docpath), '/child::section')
def test_docpath_find_nothing(self): "Test docpath find that returns None." docpath = path('paragraph') self.assertIsNone(docpath.find(self.node))
def test_docpath_find(self): "Test docpath find." docpath = path('//section') self.assertEqual( docpath.find(self.node)['names'], ['c'])