当前位置: 首页>>代码示例>>Python>>正文


Python xpath.XPathBuilder类代码示例

本文整理汇总了Python中osc2.util.xpath.XPathBuilder的典型用法代码示例。如果您正苦于以下问题:Python XPathBuilder类的具体用法?Python XPathBuilder怎么用?Python XPathBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XPathBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dummy5

 def test_dummy5(self):
     """test DummyExpression on the right hand side of "and" op"""
     xpb = XPathBuilder()
     xp = xpb.dummy()
     xp = xpb.foo & xp
     exp = '/foo'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:7,代码来源:test_xpath.py

示例2: test_path5

 def test_path5(self):
     """test descendant axis"""
     xpb = XPathBuilder()
     xp = xpb.descendant('foo').bar.descendant('baz')
     # do not use abbreviated syntax
     exp = '/descendant::foo/bar/descendant::baz'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:7,代码来源:test_xpath.py

示例3: test_dummy6

 def test_dummy6(self):
     """test DummyExpression on the right hand side of "or" op"""
     xpb = XPathBuilder()
     xp = xpb.dummy()
     xp = xpb.bar | xp
     exp = '/bar'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:7,代码来源:test_xpath.py

示例4: test_predicate10

 def test_predicate10(self):
     """test a predicate with attribute and path expression (written ops)"""
     xpb = XPathBuilder()
     pred = xpb.attr('foo').equals('bar').log_or(xpb.foobar)
     xp = xpb.foo.bar.where(pred)
     exp = '/foo/bar[@foo = "bar" or /foobar]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:7,代码来源:test_xpath.py

示例5: test_predicate4

 def test_predicate4(self):
     """test a path expression with multiple predicates (written ops)"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar.where(xpb.attr('name').not_equals('abc'))
     xp = xp.where(xpb.attr('x').equals('foo'))
     exp = '/foo/bar[@name != "abc"][@x = "foo"]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:7,代码来源:test_xpath.py

示例6: test_predicate12

 def test_predicate12(self):
     """test a "chained" predicate (written ops)"""
     xpb = XPathBuilder()
     pred = (xpb.attr('d').equals('e')
             .log_and(xpb.foo.where(xpb.attr('z').equals('abc'))))
     xp = xpb.a.b.c.where(pred)
     exp = '/a/b/c[@d = "e" and /foo[@z = "abc"]]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:8,代码来源:test_xpath.py

示例7: test_predicate8

 def test_predicate8(self):
     """test a predicate with more conditions (written ops)"""
     xpb = XPathBuilder()
     pred = (xpb.attr('name').equals('foo')
             .log_and(xpb.attr('x').equals('x')))
     xp = xpb.foo.bar.where(pred)
     exp = '/foo/bar[@name = "foo" and @x = "x"]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:8,代码来源:test_xpath.py

示例8: test_dummy1

 def test_dummy1(self):
     """test dummy method 1"""
     xpb = XPathBuilder()
     xp = xpb.dummy()
     self.assertFalse(xp)
     xp = xp & xpb.foo.bar
     self.assertTrue(xp)
     exp = '/foo/bar'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:9,代码来源:test_xpath.py

示例9: test_generator2

 def test_generator2(self):
     """test a non generator (everything happens in place) (written ops)"""
     xpb = XPathBuilder()
     xp = xpb.foo
     xp = xp.bar
     xp = xp.baz.where(xpb.attr('x').equals('y'))
     xp = xp.where(1)
     exp = '/foo/bar/baz[@x = "y"][1]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:9,代码来源:test_xpath.py

示例10: test_generator1

 def test_generator1(self):
     """test a non generator (everything happens in place)"""
     xpb = XPathBuilder()
     xp = xpb.foo
     xp = xp.bar
     xp = xp.baz[xpb.attr('x') == 'y']
     xp = xp[1]
     exp = '/foo/bar/baz[@x = "y"][1]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:9,代码来源:test_xpath.py

示例11: test_dummy2

 def test_dummy2(self):
     """test dummy method 2"""
     xpb = XPathBuilder()
     xp = xpb.dummy()
     self.assertFalse(xp)
     xp = xp & (xpb.attr('foo') == 'xyz')
     self.assertTrue(xp)
     exp = '@foo = "xyz"'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:9,代码来源:test_xpath.py

示例12: test_exception1

 def test_exception1(self):
     """test invalid expression tree"""
     xpb = XPathBuilder()
     pred = xpb.attr('foo') == 'bar'
     path = xpb.foo.bar
     pred_expr = path[pred]
     self.assertEqual(pred_expr.tostring(), '/foo/bar[@foo = "bar"]')
     pred.reparent(None)
     self.assertRaises(XPathSyntaxError, pred_expr.tostring)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:9,代码来源:test_xpath.py

示例13: test_request2

 def test_request2(self):
     """test find_request (with validation)"""
     RequestCollection.SCHEMA = self.fixture_file('collection_request.xsd')
     xpb = XPathBuilder()
     xp = xpb.state[xpb.attr('name') == 'new']
     collection = find_request(xp)
     self.assertTrue(len(collection.request[:]) == 1)
     self.assertEqual(collection.get('matches'), '1')
     self.assertEqual(collection.request[0].action.get('type'), 'submit')
     self.assertEqual(collection.request.action.get('type'), 'submit')
开发者ID:scarabeusiv,项目名称:osc2,代码行数:10,代码来源:test_search.py

示例14: test_context_item2

 def test_context_item2(self):
     """test context item (disabled) for the initial expression"""
     xpb = XPathBuilder(context_item=False)
     xp1 = xpb.foo.bar
     xp1_exp = '/foo/bar'
     xp2 = xpb.context(True).foo.bar
     xp2_exp = './foo/bar'
     self.assertEqual(xp1.tostring(), xp1_exp)
     self.assertEqual(xp2.tostring(), xp2_exp)
     self.assertFalse(xpb.context_item)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:10,代码来源:test_xpath.py

示例15: test_generator4

 def test_generator4(self):
     """test a xpath generator (written ops)"""
     xpb = XPathBuilder()
     xp1 = xp2 = None
     base_xp = xpb.base.foo.where(xpb.attr('abc').equals('x'))
     with base_xp as b:
         xp1 = b().bar.text().equals('foo')
         xp2 = b().x.y.z.where(42)
     base_exp = '/base/foo[@abc = "x"]'
     xp1_exp = '/base/foo[@abc = "x"]/bar/text() = "foo"'
     xp2_exp = '/base/foo[@abc = "x"]/x/y/z[42]'
     self.assertEqual(base_xp.tostring(), base_exp)
     self.assertEqual(xp1.tostring(), xp1_exp)
     self.assertEqual(xp2.tostring(), xp2_exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:14,代码来源:test_xpath.py


注:本文中的osc2.util.xpath.XPathBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。