summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Duponchelle <mathieu@centricular.com>2018-10-31 00:41:31 +0100
committerMathieu Duponchelle <mathieu@centricular.com>2018-10-31 00:41:31 +0100
commitd64bbc1e0c3c948c148f505cc5f856ce56732880 (patch)
tree65178deac927d9ad6269a52744d2b61eb8ced06b
parentae3ffd3ac82bf9fe2a004405b69aaaf963ad797d (diff)
Tests: refactor testing approach
Instead of fiddling with sys.path, we instead use a custom sys.meta_path importer
-rw-r--r--gi/overrides/Gst.py2
-rw-r--r--gi/overrides/meson.build9
-rw-r--r--testsuite/Makefile.am9
-rw-r--r--testsuite/meson.build5
-rw-r--r--testsuite/overrides_hack.py48
5 files changed, 32 insertions, 41 deletions
diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py
index ae18f57..2e5189b 100644
--- a/gi/overrides/Gst.py
+++ b/gi/overrides/Gst.py
@@ -566,7 +566,7 @@ def TIME_ARGS(time):
time % Gst.SECOND)
__all__.append('TIME_ARGS')
-import _gi_gst
+from gi.overrides import _gi_gst
_gi_gst
# maybe more python and less C some day if core turns a bit more introspection
diff --git a/gi/overrides/meson.build b/gi/overrides/meson.build
index 3c5a33d..b2aa334 100644
--- a/gi/overrides/meson.build
+++ b/gi/overrides/meson.build
@@ -8,12 +8,3 @@ gstpython = python.extension_module('_gi_gst',
install_dir : pygi_override_dir,
include_directories : [configinc],
dependencies : [gst_dep, python_dep, pygobject_dep])
-
-gi_overrides_build_dir = meson.current_build_dir()
-
-# Workaround to get uninstalled working.
-foreach source: pysources
- run_command(python, '-c', 'import os; os.symlink("@0@/@1@", "@2@/@3@")'.format(
- meson.current_source_dir(), source,
- gi_overrides_build_dir, source))
-endforeach
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 10b7061..a59fe47 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -1,6 +1,11 @@
# Don't try to use wildcards to replace the list of tests below.
# http://www.gnu.org/software/automake/manual/automake.html#Wildcards
# Keep this list sorted!
+
+TEST_ENVIRONMENT = \
+ GST_OVERRIDE_SRC_PATH="$(abs_top_srcdir)/gi/overrides" \
+ GST_OVERRIDE_BUILD_PATH="$(abs_top_builddir)/gi/overrides"
+
tests = \
test_gst.py \
test_types.py
@@ -20,10 +25,10 @@ clean-local:
rm -rf *.pyc *.pyo
check-local:
- $(PYTHON) $(srcdir)/runtests.py $(tests)
+ $(TEST_ENVIRONMENT) $(PYTHON) $(srcdir)/runtests.py $(tests)
%.check: %
- $(PYTHON) $(srcdir)/runtests.py $*
+ $(TEST_ENVIRONMENT) $(PYTHON) $(srcdir)/runtests.py $*
%.forever: %
$(srcdir)/cleanup.py
@while true; do \
diff --git a/testsuite/meson.build b/testsuite/meson.build
index 6fe105b..4fb573b 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -25,11 +25,10 @@ if runcmd.returncode() != 0
error('Could not configure testsuite config file.' + runcmd.stderr())
endif
-gi_dir = join_paths(pygi_override_dir, '..', '..')
-
foreach i: tests
test_name = i.get(0)
env = environment()
- env.prepend('PYTHONPATH', [gi_dir, gi_overrides_build_dir])
+ env.set('GST_OVERRIDE_SRC_PATH', join_paths (meson.current_source_dir(), '..', 'gi', 'overrides'))
+ env.set('GST_OVERRIDE_BUILD_PATH', join_paths (meson.current_build_dir(), '..', 'gi', 'overrides'))
test(test_name, python, args: [runtests, i.get(1)], env: env)
endforeach
diff --git a/testsuite/overrides_hack.py b/testsuite/overrides_hack.py
index 9094cfa..6df694d 100644
--- a/testsuite/overrides_hack.py
+++ b/testsuite/overrides_hack.py
@@ -1,32 +1,28 @@
import os
-import gi.overrides
+import sys
+import imp
-try:
- import mesonconfig
-except ImportError:
- mesonconfig = None
- pass
+class GstOverrideImport:
+ def find_module(self, fullname, path=None):
+ if fullname in ('gi.overrides.Gst', 'gi.overrides._gi_gst'):
+ return self
+ return None
-FILE = os.path.realpath(__file__)
-if not gi.overrides.__path__[0].endswith("gst-python/gi/overrides"):
- local_overrides = None
- # our overrides don't take precedence, let's fix it
- for i, path in enumerate(gi.overrides.__path__):
- if path.endswith("gst-python/gi/overrides"):
- local_overrides = path
+ def load_module(self, name):
+ if name in sys.modules:
+ return sys.modules[name]
- if local_overrides:
- gi.overrides.__path__.remove(local_overrides)
- else:
- local_overrides = os.path.abspath(os.path.join(FILE, "../", "../", "gi", "overrides"))
+ fp, pathname, description = imp.find_module(name.split('.')[-1], [
+ os.environ.get('GST_OVERRIDE_SRC_PATH'),
+ os.environ.get('GST_OVERRIDE_BUILD_PATH'),
+ ])
- gi.overrides.__path__.insert(0, local_overrides)
+ try:
+ module = imp.load_module(name, fp, pathname, description)
+ finally:
+ if fp:
+ fp.close()
+ sys.modules[name] = module
+ return module
-if mesonconfig:
- gi.overrides.__path__.insert(0, os.path.abspath(os.path.join(mesonconfig.path, "gi", "overrides")))
-# Execute previously set sitecustomize.py script if it existed
-if os.environ.get("GST_ENV"):
- old_sitecustomize = os.path.join(os.path.dirname(__file__),
- "old.sitecustomize.gstuninstalled.py")
- if os.path.exists(old_sitecustomize):
- exec(compile(open(old_sitecustomize).read(), old_sitecustomize, 'exec'))
+sys.meta_path.insert(0, GstOverrideImport())