示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
 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)
示例#9
0
 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)
示例#10
0
 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)
示例#11
0
 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)
示例#12
0
 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)
示例#13
0
 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)
示例#14
0
 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)
示例#15
0
 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)
示例#16
0
 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)
示例#17
0
 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')
示例#18
0
 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')
示例#19
0
 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)
示例#20
0
 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)
示例#21
0
 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)
示例#22
0
 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)
示例#23
0
 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)
示例#24
0
 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)
示例#25
0
 def test_predicate1(self):
     """test a path expression with simple predicate"""
     xpb = XPathBuilder()
     xp = xpb.action.source[xpb.attr('project') == 'bar']
     exp = '/action/source[@project = "bar"]'
     self.assertEqual(xp.tostring(), exp)
示例#26
0
 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)
示例#27
0
 def test_predicate13(self):
     """test contains function"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar[xpb.attr('x').contains('foo')]
     exp = '/foo/bar[contains(@x, "foo")]'
     self.assertEqual(xp.tostring(), exp)
示例#28
0
 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)
示例#29
0
 def test_predicate1(self):
     """test a path expression with simple predicate"""
     xpb = XPathBuilder()
     xp = xpb.action.source[xpb.attr('project') == 'bar']
     exp = '/action/source[@project = "bar"]'
     self.assertEqual(xp.tostring(), exp)
示例#30
0
 def test_request4(self):
     """test find_request (validation fails)"""
     RequestCollection.SCHEMA = self.fixture_file('collection_request.xsd')
     xpb = XPathBuilder()
     xp = xpb.state[xpb.attr('name') == 'declined']
     self.assertRaises(etree.DocumentInvalid, find_request, xp)
示例#31
0
 def test_predicate9(self):
     """test a predicate with attribute and path expression"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar[(xpb.attr('foo') == 'bar') | xpb.foobar]
     exp = '/foo/bar[@foo = "bar" or /foobar]'
     self.assertEqual(xp.tostring(), exp)
示例#32
0
 def test_predicate9(self):
     """test a predicate with attribute and path expression"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar[(xpb.attr('foo') == 'bar') | xpb.foobar]
     exp = '/foo/bar[@foo = "bar" or /foobar]'
     self.assertEqual(xp.tostring(), exp)
示例#33
0
 def test_predicate7(self):
     """test a predicate with more conditions"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar[(xpb.attr('name') == 'foo') & (xpb.attr('x') == 'x')]
     exp = '/foo/bar[@name = "foo" and @x = "x"]'
     self.assertEqual(xp.tostring(), exp)
示例#34
0
 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)
示例#35
0
 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)
示例#36
0
 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)
示例#37
0
 def find(self, name):
     xpb = XPathBuilder()
     xp = xpb.descendant(self._tag)[xpb.attr('name') == name]
     return self._xml.find(xp.tostring())
示例#38
0
 def test_predicate7(self):
     """test a predicate with more conditions"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar[(xpb.attr('name') == 'foo') & (xpb.attr('x') == 'x')]
     exp = '/foo/bar[@name = "foo" and @x = "x"]'
     self.assertEqual(xp.tostring(), exp)
示例#39
0
 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)
示例#40
0
 def test_predicate13(self):
     """test contains function"""
     xpb = XPathBuilder()
     xp = xpb.foo.bar[xpb.attr('x').contains('foo')]
     exp = '/foo/bar[contains(@x, "foo")]'
     self.assertEqual(xp.tostring(), exp)
示例#41
0
 def test_request4(self):
     """test find_request (validation fails)"""
     RequestCollection.SCHEMA = self.fixture_file('collection_request.xsd')
     xpb = XPathBuilder()
     xp = xpb.state[xpb.attr('name') == 'declined']
     self.assertRaises(etree.DocumentInvalid, find_request, xp)
示例#42
0
文件: util.py 项目: scarabeusiv/osc2
 def find(self, name):
     xpb = XPathBuilder()
     xp = xpb.descendant(self._tag)[xpb.attr('name') == name]
     return self._xml.find(xp.tostring())