mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 02:01:12 +00:00
Tests: refactor testing approach
Instead of fiddling with sys.path, we instead use a custom sys.meta_path importer
This commit is contained in:
parent
ae3ffd3ac8
commit
d64bbc1e0c
5 changed files with 32 additions and 41 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue