summaryrefslogtreecommitdiff
path: root/testsuite
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 /testsuite
parentae3ffd3ac82bf9fe2a004405b69aaaf963ad797d (diff)
Tests: refactor testing approach
Instead of fiddling with sys.path, we instead use a custom sys.meta_path importer
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Makefile.am9
-rw-r--r--testsuite/meson.build5
-rw-r--r--testsuite/overrides_hack.py48
3 files changed, 31 insertions, 31 deletions
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())