[pygobject] tests: support builddir != srcdir
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] tests: support builddir != srcdir
- Date: Fri, 20 Apr 2018 18:04:53 +0000 (UTC)
commit a1bb7bfb03ef713066753ed0679096db8d94e0bc
Author: Mathieu Duponchelle <mathieu centricular com>
Date: Fri Mar 16 00:41:21 2018 +0100
tests: support builddir != srcdir
tests/__init__.py | 22 ++++++++++++++++++++++
tests/test_gobject.py | 2 +-
tests/test_interface.py | 2 +-
tests/test_internal_api.py | 2 +-
tests/test_signal.py | 2 +-
tests/test_thread.py | 2 +-
tests/test_unknown.py | 2 +-
7 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/tests/__init__.py b/tests/__init__.py
index 09a20e37..437c44e7 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -7,6 +7,27 @@ import signal
import subprocess
import atexit
import warnings
+import importlib
+import sys
+import imp
+
+
+class GIImport:
+ def find_module(self, fullname, path=None):
+ if fullname == 'gi._gi':
+ return self
+ return None
+
+ def load_module(self, name):
+ if name in sys.modules:
+ return sys.modules[name]
+ module_info = imp.find_module('_gi')
+ module = imp.load_module(name, *module_info)
+ sys.modules[name] = module
+ return module
+
+
+sys.meta_path.insert(0, GIImport())
def init_test_environ():
@@ -46,6 +67,7 @@ def init_test_environ():
tests_srcdir = os.path.abspath(os.path.dirname(__file__))
srcdir = os.path.dirname(tests_srcdir)
+ sys.path.insert(0, os.path.join(builddir, 'gi'))
sys.path.insert(0, tests_srcdir)
sys.path.insert(0, srcdir)
sys.path.insert(0, tests_builddir)
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index 3f7e0089..36a6af18 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -12,7 +12,7 @@ from gi import PyGIDeprecationWarning
from gi.module import get_introspection_module
from gi import _gi
-from . import testhelper
+import testhelper
class TestGObjectAPI(unittest.TestCase):
diff --git a/tests/test_interface.py b/tests/test_interface.py
index bed37f36..ca1e0f47 100644
--- a/tests/test_interface.py
+++ b/tests/test_interface.py
@@ -5,7 +5,7 @@ from __future__ import absolute_import
import unittest
from gi.repository import GObject
-from . import testhelper
+import testhelper
GUnknown = GObject.type_from_name("TestUnknown")
diff --git a/tests/test_internal_api.py b/tests/test_internal_api.py
index 7b2b8ea5..9dcde058 100644
--- a/tests/test_internal_api.py
+++ b/tests/test_internal_api.py
@@ -9,7 +9,7 @@ import pytest
from gi.repository import GLib, GObject
from gi._compat import PY3
-from . import testhelper
+import testhelper
class PyGObject(GObject.GObject):
diff --git a/tests/test_signal.py b/tests/test_signal.py
index f4641a81..16d95c27 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -14,7 +14,7 @@ from gi import _signalhelper as signalhelper
from gi.module import repository as repo
from gi._compat import PY3, long_
-from . import testhelper
+import testhelper
from .helper import capture_glib_warnings, capture_gi_deprecation_warnings
diff --git a/tests/test_thread.py b/tests/test_thread.py
index e2bbda08..45ebd0b5 100644
--- a/tests/test_thread.py
+++ b/tests/test_thread.py
@@ -6,7 +6,7 @@ import unittest
from gi.repository import GLib
-from . import testhelper
+import testhelper
class TestThread(unittest.TestCase):
diff --git a/tests/test_unknown.py b/tests/test_unknown.py
index e483003d..1ed1fb88 100644
--- a/tests/test_unknown.py
+++ b/tests/test_unknown.py
@@ -6,7 +6,7 @@ import unittest
from gi.repository import GObject
-from . import testhelper
+import testhelper
TestInterface = GObject.GType.from_name('TestInterface')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]