From c86c582e193ad1e5bb6c4cc40f04b9ec0b52a50e Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Fri, 14 Jun 2013 23:27:13 +0200 Subject: [PATCH] Resync with the sugar-build implementation of tree.py Development continued there for a while. Now I will remove it and used the toolkit implementation instead. Changes: * Retry faster * Handle GLib errors * Don't always dump the tree * Support master atspi api --- src/sugar3/test/uitree.py | 45 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/sugar3/test/uitree.py b/src/sugar3/test/uitree.py index ad9c7f16..671b49fc 100644 --- a/src/sugar3/test/uitree.py +++ b/src/sugar3/test/uitree.py @@ -18,9 +18,11 @@ UNSTABLE. """ +import logging import time from gi.repository import Atspi +from gi.repository import GLib Atspi.set_timeout(-1, -1) @@ -34,23 +36,30 @@ def _retry_find(func): result = None n_retries = 1 - while n_retries <= 10: - print "Try %d, name=%s role_name=%s" % \ - (n_retries, - kwargs.get("name", None), - kwargs.get("role_name", None)) + while n_retries <= 50: + logging.info("Try %d, name=%s role_name=%s" % + (n_retries, + kwargs.get("name", None), + kwargs.get("role_name", None))) + + try: + result = func(*args, **kwargs) + except GLib.GError, e: + # The application is not responding, try again + if e.code == Atspi.Error.IPC: + continue + + logging.error("GError code %d", e.code) + raise - result = func(*args, **kwargs) expect_none = kwargs.get("expect_none", False) if (not expect_none and result) or \ (expect_none and not result): return result - time.sleep(5) + time.sleep(1) n_retries = n_retries + 1 - get_root().dump() - return result return wrapped @@ -61,11 +70,19 @@ class Node: self._accessible = accessible def dump(self): - self._crawl_accessible(self, 0) + lines = [] + self._crawl_accessible(self, 0, lines) + return "\n".join(lines) def do_action(self, name): for i in range(self._accessible.get_n_actions()): - if Atspi.Action.get_name(self._accessible, i) == name: + # New, incompatible API + if hasattr(self._accessible, "get_action_name"): + action_name = self._accessible.get_action_name(i) + else: + action_name = Atspi.Action.get_name(self._accessible, i) + + if action_name == name: self._accessible.do_action(i) def click(self, button=1): @@ -149,8 +166,8 @@ class Node: for child in node.get_children(): self._find_all_descendants(child, predicate, matches) - def _crawl_accessible(self, node, depth): - print " " * depth + str(node) + def _crawl_accessible(self, node, depth, lines): + lines.append(" " * depth + str(node)) for child in node.get_children(): - self._crawl_accessible(child, depth + 1) + self._crawl_accessible(child, depth + 1, lines)