[gnumeric] Tests: Ensure we load the in-tree introspection overrides.



commit d0eb944368ae079f5efe5eddfd9921c96f6b8233
Author: Morten Welinder <terra gnome org>
Date:   Wed Sep 2 21:30:53 2020 -0400

    Tests: Ensure we load the in-tree introspection overrides.
    
    The old method of just setting the python load path does not work anymore.
    
    We now hook into low levels of python to make sure that any search for
    the overrides finds the in-tree copy.
    
    This isn't elegant, but introspection doesn't seem to be built with
    testing in mind.  Any python doesn't make it easy to substitute one
    file for another.

 test/GnumericTest.pm                  |  2 +-
 test/GnumericTest.py                  | 17 +++++++++++++++++
 test/t3000-introspection-basic.py     |  4 +++-
 test/t3001-introspection-simple.py    |  4 +++-
 test/t3002-introspection-io.py        |  4 +++-
 test/t3003-introspection-plugins.py   |  4 +++-
 test/t3004-introspection-overrides.py |  4 +++-
 7 files changed, 33 insertions(+), 6 deletions(-)
---
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index 8ddf2c870..e1df58b7f 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -928,7 +928,7 @@ sub setup_python_environment {
     $dir = "$top_builddir/src/.libs";
     $ENV{$v} = ($ENV{$v} || '') eq '' ? $dir : $dir . ':' . $ENV{$v};
 
-    $ENV{'PYTHONPATH'} = "$topsrc/introspection";
+    $ENV{'GNM_TEST_INTROSPECTION_DIR'} = &make_absolute ("$topsrc/introspection/gi/overrides");
 
     # Don't litter
     $ENV{'PYTHONDONTWRITEBYTECODE'} = 1;
diff --git a/test/GnumericTest.py b/test/GnumericTest.py
new file mode 100644
index 000000000..553e3978a
--- /dev/null
+++ b/test/GnumericTest.py
@@ -0,0 +1,17 @@
+import os
+
+# -----------------------------------------------------------------------------
+# Install a hack to make sure we load the in-tree version
+
+if 'GNM_TEST_INTROSPECTION_DIR' in os.environ:
+    import importlib.machinery
+    class HackFinder:
+        def find_spec(name,path,target=None):
+            if name == 'gi.overrides.Gnm':
+                return importlib.machinery.PathFinder.find_spec (name, 
[os.environ['GNM_TEST_INTROSPECTION_DIR']])
+            return None
+
+    import sys
+    sys.meta_path = [HackFinder] + sys.meta_path
+
+# -----------------------------------------------------------------------------
diff --git a/test/t3000-introspection-basic.py b/test/t3000-introspection-basic.py
index 16f52ee3c..63ec47f05 100755
--- a/test/t3000-introspection-basic.py
+++ b/test/t3000-introspection-basic.py
@@ -1,6 +1,8 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -B
 # -----------------------------------------------------------------------------
 
+import GnumericTest
+
 import gi
 gi.require_version('Gnm', '1.12')
 from gi.repository import Gnm
diff --git a/test/t3001-introspection-simple.py b/test/t3001-introspection-simple.py
index 04ace1e27..05c63d424 100755
--- a/test/t3001-introspection-simple.py
+++ b/test/t3001-introspection-simple.py
@@ -1,6 +1,8 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -B
 # -----------------------------------------------------------------------------
 
+import GnumericTest
+
 import gi
 gi.require_version('Gnm', '1.12')
 from gi.repository import Gnm
diff --git a/test/t3002-introspection-io.py b/test/t3002-introspection-io.py
index e0ca40be6..0060f890b 100755
--- a/test/t3002-introspection-io.py
+++ b/test/t3002-introspection-io.py
@@ -1,6 +1,8 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -B
 # -----------------------------------------------------------------------------
 
+import GnumericTest
+
 import gi
 gi.require_version('Gnm', '1.12')
 gi.require_version('GOffice', '0.10')
diff --git a/test/t3003-introspection-plugins.py b/test/t3003-introspection-plugins.py
index 28a69acb8..eaa8e9978 100755
--- a/test/t3003-introspection-plugins.py
+++ b/test/t3003-introspection-plugins.py
@@ -1,6 +1,8 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -B
 # -----------------------------------------------------------------------------
 
+import GnumericTest
+
 import gi
 gi.require_version('Gnm', '1.12')
 gi.require_version('GOffice', '0.10')
diff --git a/test/t3004-introspection-overrides.py b/test/t3004-introspection-overrides.py
index 460947b7a..ae6438c4b 100755
--- a/test/t3004-introspection-overrides.py
+++ b/test/t3004-introspection-overrides.py
@@ -1,6 +1,8 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -B
 # -----------------------------------------------------------------------------
 
+import GnumericTest
+
 import gi
 gi.require_version('Gnm', '1.12')
 from gi.repository import Gnm


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