Author: Armin Rigo <[email protected]>
Branch:
Changeset: r3174:448af882f47e
Date: 2018-11-29 18:24 +0000
http://bitbucket.org/cffi/cffi/changeset/448af882f47e/
Log: Merged in rlamy/cffi (pull request #94)
Move test-only function from cffi/ to testing/
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -1540,27 +1540,3 @@
else:
return None, updated
-def _verify(ffi, module_name, preamble, *args, **kwds):
- # FOR TESTS ONLY
- from testing.udir import udir
- import imp
- assert module_name not in sys.modules, "module name conflict: %r" % (
- module_name,)
- kwds.setdefault('tmpdir', str(udir))
- outputfilename = recompile(ffi, module_name, preamble, *args, **kwds)
- module = imp.load_dynamic(module_name, outputfilename)
- #
- # hack hack hack: copy all *bound methods* from module.ffi back to the
- # ffi instance. Then calls like ffi.new() will invoke module.ffi.new().
- for name in dir(module.ffi):
- if not name.startswith('_'):
- attr = getattr(module.ffi, name)
- if attr is not getattr(ffi, name, object()):
- setattr(ffi, name, attr)
- def typeof_disabled(*args, **kwds):
- raise NotImplementedError
- ffi._typeof = typeof_disabled
- for name in dir(ffi):
- if not name.startswith('_') and not hasattr(module.ffi, name):
- setattr(ffi, name, NotImplemented)
- return module.lib
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -4,7 +4,7 @@
from cffi import recompiler
from testing.udir import udir
from testing.support import u, long
-from testing.support import FdWriteCapture, StdErrCapture
+from testing.support import FdWriteCapture, StdErrCapture, _verify
try:
import importlib
@@ -35,7 +35,7 @@
# add '-Werror' to the existing 'extra_compile_args' flags
kwds['extra_compile_args'] = (kwds.get('extra_compile_args', []) +
['-Werror'])
- return recompiler._verify(ffi, module_name, source, *args, **kwds)
+ return _verify(ffi, module_name, source, *args, **kwds)
def test_set_source_no_slashes():
ffi = FFI()
diff --git a/testing/cffi1/test_verify1.py b/testing/cffi1/test_verify1.py
--- a/testing/cffi1/test_verify1.py
+++ b/testing/cffi1/test_verify1.py
@@ -3,6 +3,7 @@
from cffi import CDefError
from cffi import recompiler
from testing.support import *
+from testing.support import _verify
import _cffi_backend
lib_m = ['m']
@@ -37,9 +38,8 @@
except AttributeError:
pass
self.set_source(module_name, preamble)
- return recompiler._verify(self, module_name, preamble, *args,
- extra_compile_args=self._extra_compile_args,
- **kwds)
+ return _verify(self, module_name, preamble, *args,
+ extra_compile_args=self._extra_compile_args, **kwds)
class FFI_warnings_not_error(FFI):
_extra_compile_args = []
diff --git a/testing/support.py b/testing/support.py
--- a/testing/support.py
+++ b/testing/support.py
@@ -61,3 +61,28 @@
def getvalue(self):
return self._value
+
+def _verify(ffi, module_name, preamble, *args, **kwds):
+ import imp
+ from cffi.recompiler import recompile
+ from .udir import udir
+ assert module_name not in sys.modules, "module name conflict: %r" % (
+ module_name,)
+ kwds.setdefault('tmpdir', str(udir))
+ outputfilename = recompile(ffi, module_name, preamble, *args, **kwds)
+ module = imp.load_dynamic(module_name, outputfilename)
+ #
+ # hack hack hack: copy all *bound methods* from module.ffi back to the
+ # ffi instance. Then calls like ffi.new() will invoke module.ffi.new().
+ for name in dir(module.ffi):
+ if not name.startswith('_'):
+ attr = getattr(module.ffi, name)
+ if attr is not getattr(ffi, name, object()):
+ setattr(ffi, name, attr)
+ def typeof_disabled(*args, **kwds):
+ raise NotImplementedError
+ ffi._typeof = typeof_disabled
+ for name in dir(ffi):
+ if not name.startswith('_') and not hasattr(module.ffi, name):
+ setattr(ffi, name, NotImplemented)
+ return module.lib
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit