Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions tests/test_gtk_version_pin.py
Original file line number Diff line number Diff line change
@@ -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")