Cannot select int or bool properties without class

Bug #1194763 reported by Martin Pitt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Autopilot
Fix Released
High
Unassigned
XPathSelect
Fix Released
High
Unassigned
autopilot-gtk
Fix Released
High
Unassigned

Bug Description

While select_{single,many}() works fine for string properties, they do not work for int or bool properties: self.app.select_many(border_width=5) always returns [] (although there are 3 widgets with that in my project), self.app.select_single(border_width=2) always returns None (although there is one widget), and self.app.select_many(visible=True) or self.app.select_many(visible=1) always return [].

Tags: has-testcase

Related branches

Revision history for this message
Martin Pitt (pitti) wrote :
Changed in autopilot-gtk:
status: New → Triaged
importance: Undecided → High
assignee: nobody → Martin Pitt (pitti)
Revision history for this message
Martin Pitt (pitti) wrote :

Keeping notes: What does work is to specify a class name:

   res = self.app.select_many('GtkButtonBox', border_width=5)
   res = self.app.select_many('GtkButton', visible=True)

These generate the query strings "/Root[id=1]//GtkButtonBox" and "/Root[id=1]//GtkButton" respectively (in ./autopilot/introspection/dbus.py select_many()); these retrieve the full list of widgets of the corresponding class, and object_passes_filters() correctly filters them.

But if I don't specify a class, as in the description, I see:

11:03:59.842 DEBUG dbus:368 - query /Root[id=1]//* got state dbus.Array([], signature=dbus.Signature('(sv)'))

(that's an added debug statement in autopilot from my side), so queries using "*" don't work at the moment. Looking whether that's autopilot-gtk specific or a bug in autopilot itself.

Revision history for this message
Martin Pitt (pitti) wrote :

For the record, with string properties select_many() builds the query string "/Root[id=1]//*[label=gtk-delete]" which does work.

summary: - Cannot select int or bool properties
+ Cannot select int or bool properties without class
Revision history for this message
Martin Pitt (pitti) wrote :

I believe this is actually a bug in xpathselect which fails to understand queries of the form "/Root[id=1]//*". I attach a patch which adds a test case. This currently fails:

[ RUN ] TestTreeFixture.test_search_all_nodes_with_wildcard_and_root_property
/home/martin/upstream/xpathselect/test/test_xpath_tree.cpp:180: Failure
Value of: result.size()
  Actual: 0
Expected: 5

Changed in autopilot-gtk:
status: Triaged → Invalid
tags: added: has-testcase
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Martin,

The query you use in your test case ("/Root[id=1]//*") is invalid, and should not work. The reason is that "//*" will match every node in the tree, and is explicitly disallowed. Autopilot should never be generating queries like that - if it is, then it's a bug against autopilot. I'm marking the task against xpathselect as invalid, since the test case you supplied is invalid. If you like, perhaps schedule a call on my calendar so we can get to the bottom of this together. I guess early in my timezone is probably going to be the most suitable.

Cheers,

Changed in xpathselect:
status: New → Invalid
Revision history for this message
Martin Pitt (pitti) wrote :

"//*" is allowed by xpath, at least it is shown in http://www.w3schools.com/xpath/xpath_syntax.asp and the grammar on http://www.w3.org/TR/xpath also allows it. But anyway, if you don't want to support this in xpathselect, we need to fix it in autopilot, as it is generating exactly this query: http://bazaar.launchpad.net/~autopilot/autopilot/trunk/view/head:/autopilot/introspection/dbus.py#L311

I. e. type_name defaults to "*" if you don't specify a class, get_class_query_string() returns "//Root[id=1]", and this:

        query_path = "%s//%s%s" % (self.get_class_query_string(),
                                   type_name,
                                   first_param)

finally appends the type_name there, resulting in "/Root[id=1]//*". The XPath semantics should indeed be "return all nodes, as the code in select_many currently does not support non-string attributes or (for some reason) values which contain '_'. These are filtered on the client side with object_passes_filters().

So I guess I'll leave it to you if you want to implement this in xpathselect or change the code in autopilot.

Revision history for this message
Martin Pitt (pitti) wrote :

IRC summary: while this is valid XPath syntax, it's not a wanted feature in the context of xpathselect. The intention is that select_many() never asks for all nodes, but always specifies attribute filters. So we need to teach it to stringify the value instead of limiting attributes to string values, and also drop the curious limitation of not allowing '_' in property names. So the current bug title is quite appropriate.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Martin,

I just looked at working around this in autopilot, and it's more complex than I thought. The only thing I can think to do to stop people running into this bug is to raise an exception in autopilot when they both specify '*' as the type name, and a non-string value as the keyword value.

Perhaps it's time to give this bug some development time, to fix it properly. It's something to think about anyway.

Changed in autopilot-gtk:
assignee: Martin Pitt (pitti) → Thomi Richards (thomir)
status: Invalid → In Progress
Changed in xpathselect:
status: Invalid → In Progress
assignee: nobody → Thomi Richards (thomir)
importance: Undecided → High
Changed in autopilot:
status: New → In Progress
assignee: nobody → Thomi Richards (thomir)
importance: Undecided → High
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

Fix committed into lp:xpathselect at revision 38, scheduled for release in xpathselect, milestone 1.3

Changed in xpathselect:
status: In Progress → Fix Committed
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

Fix committed into lp:autopilot-gtk at revision 53, scheduled for release in autopilot-gtk, milestone Unknown

Changed in autopilot-gtk:
status: In Progress → Fix Committed
Changed in autopilot:
milestone: none → 1.4
status: In Progress → Fix Committed
Changed in autopilot:
status: Fix Committed → Fix Released
Changed in xpathselect:
status: Fix Committed → Fix Released
Changed in autopilot-gtk:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.