2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008 Colin Walters
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
21 from .girparser import C_NS, GLIB_NS
22 from .girparser import _corens
28 def myxpath(node, expr):
29 """I Can't Believe It's Not XPath!"""
30 elts = expr.split('/')
36 (elt, qual) = elt.split('[', 1)
38 pairs = [x.split('=', 1) for x in qual.split(',')]
39 exp_attrs = [(x[0], x[1][1:-1]) for x in pairs]
41 (elt, exp_attrs) = (elt, [])
43 (ns, elt) = elt.split(':', 1)
45 elt = '{%s}%s' % (ns, elt)
48 curnodes = curnode.findall(elt)
52 #print "LOOKING %d nodes" % (len(curnodes), )
54 #print "LOOKING: %r expecting: %r attrib: %r" \
55 # % (node, exp_attrs, node.attrib)
57 for name, val in exp_attrs:
58 a = node.attrib.get(name)
60 #print "ATTR FAIL: %r=%r" % (val, a)
65 #print 'ATTR PASS: %r' % (node, )
74 def xpath_assert(node, path, attribs=[]):
75 elt = myxpath(node, path)
77 raise AssertionError("Failed to find %r" % (path, ))
78 for (name, expvalue) in attribs:
79 value = elt.attrib.get(name)
81 raise AssertionError("Failed to find attibute %r" +
82 "in node %r" % (name, elt, ))
84 raise AssertionError("Attibute %r in node %r has " +
85 "unexpected value %r" % (name, elt, expvalue))