diff --git a/tests/__init__.py b/tests/__init__.py index e69de29bb..ff68cee43 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,19 @@ +"""Pin the GTK / GDK introspection versions for the repo-root test suite. + +``python3 -m unittest discover -s tests`` imports this package before any test +module under ``tests/``, so requiring the versions here pins the whole suite to +the GTK 3 / GDK 3 stack a real Gramps GUI session uses. A test that imports a +``gramps.gui.*`` module directly never runs the launcher's own +``require_version``; without this the GI stack can resolve to GTK 4 on a host +where that is the default — emitting ``PyGIWarning`` and risking the wrong stack. +""" + +try: + import gi + + gi.require_version("Gdk", "3.0") + gi.require_version("Gtk", "3.0") +except Exception: + # No PyGObject, or the 3.0 typelibs are unavailable — leave the environment + # untouched; this only fixes the version when it can. + pass diff --git a/tests/test_gtk_version_pin.py b/tests/test_gtk_version_pin.py new file mode 100644 index 000000000..3d9c32633 --- /dev/null +++ b/tests/test_gtk_version_pin.py @@ -0,0 +1,18 @@ +"""Guard: the repo-root test suite pins GTK/GDK to 3 (via tests/__init__.py).""" + +import unittest + + +class GtkGdkVersionPin(unittest.TestCase): + def test_suite_pins_gtk_and_gdk_to_3(self): + try: + import gi + except ImportError: + self.skipTest("PyGObject not available") + repo = gi.Repository.get_default() + if "3.0" not in repo.enumerate_versions("Gtk") or \ + "3.0" not in repo.enumerate_versions("Gdk"): + self.skipTest("GTK/GDK 3.0 introspection typelibs not installed") + # Importing the tests package ran tests/__init__.py, which must pin both. + self.assertEqual(gi.get_required_version("Gtk"), "3.0") + self.assertEqual(gi.get_required_version("Gdk"), "3.0")