[at-spi2-core: 35/47] tests/registryd: Start a testsuite for the registry




commit 351dfae1cee6150df274458c4d74280575d44f78
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jul 12 12:27:04 2022 -0500

    tests/registryd: Start a testsuite for the registry
    
    This is done using pytest, because it allows us to easily create
    fixtures with clean teardown: we want to launch a registry daemon, and
    terminate it cleanly via a gnome-session mock.

 tests/registryd/conftest.py              | 52 ++++++++++++++++++++++++++++++++
 tests/registryd/test_registry_startup.py |  6 ++++
 2 files changed, 58 insertions(+)
---
diff --git a/tests/registryd/conftest.py b/tests/registryd/conftest.py
new file mode 100644
index 00000000..738a5836
--- /dev/null
+++ b/tests/registryd/conftest.py
@@ -0,0 +1,52 @@
+# This file contains common test fixtures for registryd's tests.
+# Using pytest's terminology for a test's steps:
+#
+# 1. Arrange: create a test fixture; this usually involves a running registry and an accessible app stub.
+#
+# 2. Act: manipulate the app or the registry.
+#
+# 3. Assert: ensure that the thing being manipulated is in the expected state.
+#
+# 4. Cleanup: Terminate the registry and the app.  It is important that the registry exits cleanly,
+#    so it can write out its code coverage information.
+#
+# This module exports the following fixtures:
+#
+# * main_loop - a GLib.MainLoop integrated with the DBusGMainLoop.
+#
+# * session_manager - A mock gnome-session to control the lifetime of daemons.
+#
+# * registry - A dbus.proxies.ProxyObject for the registry's root object.  This automatically
+#   depends on a session_manager fixture to control its lifetime.
+
+import pytest
+import dbus
+
+@pytest.fixture
+def main_loop():
+    from dbus.mainloop.glib import DBusGMainLoop
+    from gi.repository import GLib
+
+    DBusGMainLoop(set_as_default=True)
+    loop = GLib.MainLoop()
+    print("main loop created")
+    return loop
+
+def get_accesssibility_bus_address():
+    bus = dbus.SessionBus()
+    bus_launcher = bus.get_object('org.a11y.Bus', '/org/a11y/bus')
+    return str(bus_launcher.GetAddress(dbus_interface='org.a11y.Bus'))
+
+def get_registry_root(a11y_bus):
+    return a11y_bus.get_object('org.a11y.atspi.Registry', '/org/a11y/atspi/accessible/root')
+
+@pytest.fixture
+def session_manager():
+    return None # FIXME - return a gnome-session mock
+
+@pytest.fixture
+def registry(main_loop, session_manager):
+    a11y_address = get_accesssibility_bus_address()
+    a11y_bus = dbus.bus.BusConnection(a11y_address)
+
+    return get_registry_root(a11y_bus)
diff --git a/tests/registryd/test_registry_startup.py b/tests/registryd/test_registry_startup.py
new file mode 100644
index 00000000..df23fede
--- /dev/null
+++ b/tests/registryd/test_registry_startup.py
@@ -0,0 +1,6 @@
+PROPERTIES_IFACE = 'org.freedesktop.DBus.Properties'
+ACCESSIBLE_IFACE = 'org.a11y.atspi.Accessible'
+
+def test_accessible_iface_properties(registry, session_manager):
+    val = registry.Get(ACCESSIBLE_IFACE, 'Name', dbus_interface=PROPERTIES_IFACE)
+    assert str(val) == 'main'


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