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


Python XPathBuilder.attr方法代码示例

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


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

示例1: test_predicate4

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:9,代码来源:test_xpath.py

示例2: test_predicate8

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:10,代码来源:test_xpath.py

示例3: test_predicate12

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:10,代码来源:test_xpath.py

示例4: test_predicate10

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:9,代码来源:test_xpath.py

示例5: test_generator1

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:11,代码来源:test_xpath.py

示例6: test_generator2

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:11,代码来源:test_xpath.py

示例7: test_exception1

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:11,代码来源:test_xpath.py

示例8: test_dummy2

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:11,代码来源:test_xpath.py

示例9: test_request2

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:12,代码来源:test_search.py

示例10: test_request1

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 def test_request1(self):
     """test find_request"""
     xpb = XPathBuilder()
     xp = xpb.state[(xpb.attr('name') == 'new')
                    | (xpb.attr('name') == 'review')]
     xp = xp & (xpb.action.target[xpb.attr('project') == 'prj']
                | xpb.action.source[xpb.attr('project') == 'prj']
                ).parenthesize()
     collection = find_request(xp)
     self.assertTrue(len(collection.request[:]) == 3)
     self.assertEqual(collection.request[0].get('id'), '1')
     self.assertEqual(collection.request[0].action.source.get('project'),
                      'foo')
     self.assertEqual(collection.request[1].get('id'), '42')
     self.assertEqual(collection.request[1].action.get('type'), 'submit')
     self.assertEqual(collection.request[2].get('id'), '108')
     self.assertEqual(collection.request[2].review[2].get('by_group'),
                      'autobuild-team')
     # test __iter__ method of the collection
     ids = ['1', '42', '108']
     for r in collection:
         self.assertEqual(r.get('id'), ids.pop(0))
     self.assertTrue(len(ids) == 0)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:25,代码来源:test_search.py

示例11: test_generator4

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 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,代码行数:16,代码来源:test_xpath.py

示例12: test_generator3

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 def test_generator3(self):
     """test a xpath generator"""
     xpb = XPathBuilder()
     xp1 = xp2 = None
     base_xp = xpb.base.foo[xpb.attr('abc') == 'x']
     with base_xp as b:
         xp1 = b().bar.text() == 'foo'
         xp2 = b().x.y.z[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,代码行数:16,代码来源:test_xpath.py

示例13: test_predicate11

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 def test_predicate11(self):
     """test a "chained" predicate"""
     xpb = XPathBuilder()
     xp = xpb.a.b.c[(xpb.attr('d') == 'e') & xpb.foo[xpb.attr('z') == 'ab']]
     exp = '/a/b/c[@d = "e" and /foo[@z = "ab"]]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:8,代码来源:test_xpath.py

示例14: test_predicate2

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 def test_predicate2(self):
     """test a path expression with simple predicate (written ops)"""
     xpb = XPathBuilder()
     xp = xpb.action.source.where(xpb.attr('project').equals('bar'))
     exp = '/action/source[@project = "bar"]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:8,代码来源:test_xpath.py

示例15: test_predicate3

# 需要导入模块: from osc2.util.xpath import XPathBuilder [as 别名]
# 或者: from osc2.util.xpath.XPathBuilder import attr [as 别名]
 def test_predicate3(self):
     """test a path expression with multiple predicates"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar[xpb.attr('name') != 'abc'][xpb.attr('x') == 'foo']
     exp = '/foo/bar[@name != "abc"][@x = "foo"]'
     self.assertEqual(xp.tostring(), exp)
开发者ID:scarabeusiv,项目名称:osc2,代码行数:8,代码来源:test_xpath.py


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