summaryrefslogtreecommitdiff
path: root/runtests.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2021-06-14 16:45:15 +0200
committerStefan Behnel <stefan_ml@behnel.de>2021-06-14 17:00:54 +0200
commite10bd48a43b2652fe93ea509e6fa95780801f682 (patch)
tree7a8b09a712944ceec36ccea88eea47436abc454f /runtests.py
parent48325b43e2f3107e07723ef209ed1ce1528aa956 (diff)
downloadcython-e10bd48a43b2652fe93ea509e6fa95780801f682.tar.gz
Automatically add stubs for "cython.cimports.*" in the test runner to make them importable in Python (although not necessarily runnable).
Diffstat (limited to 'runtests.py')
-rwxr-xr-xruntests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/runtests.py b/runtests.py
index 3dd27fcbc..702fc3a02 100755
--- a/runtests.py
+++ b/runtests.py
@@ -980,6 +980,15 @@ class CythonCompileTestCase(unittest.TestCase):
if self.workdir not in sys.path:
sys.path.insert(0, self.workdir)
+ if self.add_cython_import:
+ with open(self.module_path, 'rb') as f:
+ source = f.read()
+ if b'cython.cimports.' in source:
+ from Cython.Shadow import CythonCImports
+ for name in set(re.findall(br"(cython\.cimports(?:\.\w+)+)", source)):
+ name = name.decode()
+ sys.modules[name] = CythonCImports(name)
+
def tearDown(self):
from Cython.Compiler import Options
for name, value in self._saved_options:
@@ -995,6 +1004,13 @@ class CythonCompileTestCase(unittest.TestCase):
del sys.modules[self.module]
except KeyError:
pass
+
+ # remove any stubs of cimported modules in pure Python mode
+ if self.add_cython_import:
+ for name in list(sys.modules):
+ if name.startswith('cython.cimports.'):
+ del sys.modules[name]
+
cleanup = self.cleanup_failures or self.success
cleanup_c_files = WITH_CYTHON and self.cleanup_workdir and cleanup
cleanup_lib_files = self.cleanup_sharedlibs and cleanup