summaryrefslogtreecommitdiff
path: root/testing/support.py
diff options
context:
space:
mode:
authorRonan Lamy <ronan.lamy@gmail.com>2018-11-27 18:40:23 +0000
committerRonan Lamy <ronan.lamy@gmail.com>2018-11-27 18:40:23 +0000
commitee96fd83fe5883ac5b5f7880cfbc959f9bf90b4b (patch)
treede4c55110830c51df6b539aa61e9879f557c5f5d /testing/support.py
parent9178ac12a645f71749b273cc630d41b98001ad6a (diff)
downloadcffi-ee96fd83fe5883ac5b5f7880cfbc959f9bf90b4b.tar.gz
Move test-only function from cffi/ to testing/
Diffstat (limited to 'testing/support.py')
-rw-r--r--testing/support.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/testing/support.py b/testing/support.py
index c26bc91..65f010c 100644
--- a/testing/support.py
+++ b/testing/support.py
@@ -61,3 +61,28 @@ class FdWriteCapture(object):
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