Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/sugar
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2012-11-29 18:58:42 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2012-11-29 18:58:42 (GMT)
commit69982ce0d1b712ccfe5797fb83721ab856ec951b (patch)
treeb7bafcd29292a7b7defaa79369e90eeefaa17285 /tests/sugar
parent747b165600dd1c7787ca0aed73d6f75a69959961 (diff)
Move the sugar tests
To make space for the devbot ones
Diffstat (limited to 'tests/sugar')
-rw-r--r--tests/sugar/shell.py83
-rw-r--r--tests/sugar/tree.py131
2 files changed, 214 insertions, 0 deletions
diff --git a/tests/sugar/shell.py b/tests/sugar/shell.py
new file mode 100644
index 0000000..25bd34d
--- /dev/null
+++ b/tests/sugar/shell.py
@@ -0,0 +1,83 @@
+import sys
+import time
+
+import tree
+
+ACTIVITIES_WITH_OBJECT_CHOOSER = ["Read", "Jukebox"]
+
+def build_activities_list():
+ root = tree.get_root()
+ shell = root.find_child(name="sugar-session", role_name="application")
+
+ activities = []
+
+ table = shell.find_child(role_name="table")
+ cells = table.find_children(role_name="table cell")
+
+ for row in [cells[i:i+5] for i in range(0, len(cells), 5)]:
+ activity_name = row[2].text
+ activities.append(activity_name)
+
+ activities.sort()
+
+ return activities
+
+def launch_and_stop_activity(activity_name):
+ print "Launching %s" % activity_name
+
+ root = tree.get_root()
+ shell = root.find_child(name="sugar-session", role_name="application")
+
+ table = shell.find_child(role_name="table")
+ cells = table.find_children(role_name="table cell")
+
+ for row in [cells[i:i+5] for i in range(0, len(cells), 5)]:
+ name = row[2].name
+ icon = row[1]
+
+ if name == activity_name:
+ icon.click()
+
+ print "Stopping %s" % activity_name
+
+ if activity_name in ACTIVITIES_WITH_OBJECT_CHOOSER:
+ close_button = shell.find_child(name="Close",
+ role_name="push button")
+ close_button.do_action("click")
+
+ activity = root.find_child(name="sugar-activity",
+ role_name="application")
+
+ stop_buttons = activity.find_children(name="Stop",
+ role_name="push button")
+ stop_buttons[-1].do_action("click")
+
+ activity = root.find_child(name="sugar-activity",
+ role_name="application",
+ expect_none=True)
+ if activity is not None:
+ raise RuntimeError
+
+def go_to_list_view():
+ root = tree.get_root()
+ shell = root.find_child(name="sugar-session", role_name="application")
+
+ done_button = shell.find_child(name="Done", role_name="push button")
+ done_button.do_action("click")
+
+ gcr_prompter = root.find_child(name="gcr-prompter", role_name="application")
+ if gcr_prompter:
+ cancel_button = gcr_prompter.find_child(name="Cancel",
+ role_name="push button")
+ cancel_button.do_action("click")
+
+ radio_button = shell.find_child(name="List view", role_name="radio button")
+ radio_button.do_action("click")
+
+def main():
+ go_to_list_view()
+
+ for activity in build_activities_list():
+ launch_and_stop_activity(activity)
+
+main()
diff --git a/tests/sugar/tree.py b/tests/sugar/tree.py
new file mode 100644
index 0000000..6f61004
--- /dev/null
+++ b/tests/sugar/tree.py
@@ -0,0 +1,131 @@
+import time
+
+from gi.repository import Atspi
+
+def get_root():
+ return Node(Atspi.get_desktop(0))
+
+def _retry_find(func):
+ def wrapped(*args, **kwargs):
+ 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))
+
+ 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)
+ n_retries = n_retries + 1
+
+ get_root().dump()
+
+ return result
+
+ return wrapped
+
+class Node:
+ def __init__(self, accessible):
+ self._accessible = accessible
+
+ def dump(self):
+ self._crawl_accessible(self, 0)
+
+ def do_action(self, name):
+ for i in range(self._accessible.get_n_actions()):
+ if Atspi.Action.get_name(self._accessible, i) == name:
+ self._accessible.do_action(i)
+
+ def click(self, button=1):
+ point = self._accessible.get_position(Atspi.CoordType.SCREEN)
+ Atspi.generate_mouse_event(point.x, point.y, "b%sc" % button)
+
+ @property
+ def name(self):
+ return self._accessible.get_name()
+
+ @property
+ def role_name(self):
+ return self._accessible.get_role_name()
+
+ @property
+ def text(self):
+ return Atspi.Text.get_text(self._accessible, 0, -1)
+
+ def get_children(self):
+ children = []
+
+ for i in range(self._accessible.get_child_count()):
+ child = self._accessible.get_child_at_index(i)
+
+ # We sometimes get none children from atspi
+ if child is not None:
+ children.append(Node(child))
+
+ return children
+
+ @_retry_find
+ def find_children(self, name=None, role_name=None):
+ def predicate(node):
+ return self._predicate(node, name, role_name)
+
+ descendants = []
+ self._find_all_descendants(self, predicate, descendants)
+ if not descendants:
+ return []
+
+ return descendants
+
+ @_retry_find
+ def find_child(self, name=None, role_name=None, expect_none=False):
+ def predicate(node):
+ return self._predicate(node, name, role_name)
+
+ node = self._find_descendant(self, predicate)
+ if node is None:
+ return None
+
+ return node
+
+ def __str__(self):
+ return "[%s | %s]" % (self.name, self.role_name)
+
+ def _predicate(self, node, name, role_name):
+ if name is not None and name != node.name:
+ return False
+
+ if role_name is not None and role_name != node.role_name:
+ return False
+
+ return True
+
+ def _find_descendant(self, node, predicate):
+ if predicate(node):
+ return node
+
+ for child in node.get_children():
+ descendant = self._find_descendant(child, predicate)
+ if descendant is not None:
+ return descendant
+
+ return None
+
+ def _find_all_descendants(self, node, predicate, matches):
+ if predicate(node):
+ matches.append(node)
+
+ for child in node.get_children():
+ self._find_all_descendants(child, predicate, matches)
+
+ def _crawl_accessible(self, node, depth):
+ print " " * depth + str(node)
+
+ for child in node.get_children():
+ self._crawl_accessible(child, depth + 1)