[gnome-weather] Add tests for the world view



commit 5ef47015d89a8bfbc9cc3b0af5c9024e2bd1436e
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Feb 3 16:55:16 2014 +0100

    Add tests for the world view
    
    Test entering/exiting selection mode, test deleting items, test
    adding items by modifying settings

 tests/Makefile.am   |    3 +-
 tests/testutil.py   |   67 +++++++++++++++++++++++++++++++++++
 tests/world_view.py |   97 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5663032..86e740c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,5 +2,6 @@ if ENABLE_DOGTAIL
 include $(top_srcdir)/glib-tap.mk
 
 dist_test_scripts = \
-       basic.py
+       world_view.py
+dist_test_data = testutil.py
 endif
diff --git a/tests/testutil.py b/tests/testutil.py
new file mode 100644
index 0000000..de90d49
--- /dev/null
+++ b/tests/testutil.py
@@ -0,0 +1,67 @@
+# -*- mode: python -*-
+
+from gi.repository import GLib, Gio
+from dogtail import tree
+from dogtail import utils
+from dogtail.predicate import *
+from dogtail.procedural import *
+
+APPLICATION_ID = "org.gnome.Weather.Application"
+
+_bus = None
+
+class IsTextEqual(Predicate):
+    """Predicate subclass that looks for top-level windows"""
+    def __init__(self, text):
+        self.text = text
+
+    def satisfiedByNode(self, node):
+        try:
+            textIface = node.queryText()
+            #print textIface.getText(0, -1)
+            return textIface.getText(0, -1) == self.text
+        except NotImplementedError:
+            return False
+
+    def describeSearchResult(self):
+        return '%s text node' % self.text
+
+def _do_bus_call(method, params):
+    global _bus
+
+    if _bus == None:
+        _bus = Gio.bus_get_sync(Gio.BusType.SESSION)
+    _bus.call_sync(APPLICATION_ID, '/' + APPLICATION_ID.replace('.', '/'),
+                   'org.freedesktop.Application',
+                   method, params, None,
+                   Gio.DBusCallFlags.NONE,
+                   -1, None)
+
+def start():
+    _do_bus_call("Activate", GLib.Variant('(a{sv})', ([],)))
+    utils.doDelay(2)
+
+    app = tree.root.application(APPLICATION_ID)
+    focus.application(APPLICATION_ID)
+
+    return app
+
+def reset_settings():
+    # need to go through the parser because pygobject does not handle maybe types
+    parsed = GLib.Variant.parse(GLib.VariantType.new('av'),
+                                "[<(uint32 1, <('Linate Airport', 'LIML', "
+                                "false, @m(dd) (0.79296125100499293, "
+                                "0.16202472640904275), @m(dd) (0.79354303905785273, "
+                                "0.16057029118347829))>)>]")
+    settings.set_value("locations", parsed)
+
+def init():
+    global settings, _previous_locations
+
+    settings = Gio.Settings(schema_id="org.gnome.Weather.Application")
+    _previous_locations = settings.get_value("locations")
+    reset_settings()
+
+def fini():
+    settings.set_value("locations", _previous_locations)
+    _do_bus_call("ActivateAction", GLib.Variant('(sava{sv})', ('quit', [], [])))
diff --git a/tests/world_view.py b/tests/world_view.py
new file mode 100755
index 0000000..b27b5b1
--- /dev/null
+++ b/tests/world_view.py
@@ -0,0 +1,97 @@
+#! /usr/bin/python
+
+from gi.repository import Gio, GLib
+
+import os, sys
+import pyatspi
+from dogtail import tree
+from dogtail import utils
+from dogtail.procedural import *
+from testutil import *
+
+def active(widget):
+    return widget.getState().contains(pyatspi.STATE_ARMED)
+def visible(widget):
+    return widget.getState().contains(pyatspi.STATE_VISIBLE)
+
+init()
+try:
+    app = start()
+
+    new_button = app.child('New')
+    back_button = app.child('Back')
+    delete_button = app.child('Delete')
+    select_button = app.child('Select')
+    done_button = app.child('Cancel')
+    world_view = app.child('World view')
+    city_view = app.child('City view')
+    content_view = app.child('Cities')
+    milan_icon = content_view.findChild(IsTextEqual('Milan'))
+
+    # basic state
+    assert new_button.showing
+    assert not back_button.showing
+    assert not delete_button.showing
+    assert select_button.showing
+    assert not done_button.showing
+    assert world_view.showing
+    assert content_view.showing
+    assert not city_view.showing
+
+    # selection mode
+    select_button.click()
+    assert not new_button.showing
+    assert not back_button.showing
+    assert delete_button.showing
+    assert not delete_button.sensitive
+    assert not select_button.showing
+    assert done_button.showing
+    assert world_view.showing
+    assert content_view.showing
+    assert not city_view.showing
+
+    # select one
+    milan_icon.click()
+    assert delete_button.sensitive
+    # unselect it
+    milan_icon.click()
+    assert not delete_button.sensitive
+
+    # back from selection mode
+    done_button.click()
+    assert new_button.showing
+    assert not back_button.showing
+    assert not delete_button.showing
+    assert select_button.showing
+    assert not done_button.showing
+    assert world_view.showing
+    assert content_view.showing
+    assert not city_view.showing
+
+    # back into selection mode, delete the only item
+    select_button.click()
+    milan_icon.click()
+    delete_button.click()
+    assert milan_icon.dead
+    placeholder = app.child('Add locations').parent
+    assert placeholder.showing
+    assert select_button.showing
+    assert not select_button.sensitive
+
+    # reset
+    reset_settings()
+    utils.doDelay(1)
+    milan_icon = content_view.findChild(IsTextEqual('Milan'))
+    assert not milan_icon.dead
+    # these two should be equivalend to milan_icon.showing,
+    # but for some reason they aren't
+    assert visible(milan_icon)
+    assert milan_icon.parent.showing
+
+finally:
+    fini()
+
+#type("gimp\n")
+#doDelay(2)
+#keyCombo("Escape")
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]