本文整理匯總了Python中testing.udir.udir方法的典型用法代碼示例。如果您正苦於以下問題:Python udir.udir方法的具體用法?Python udir.udir怎麽用?Python udir.udir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類testing.udir
的用法示例。
在下文中一共展示了udir.udir方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _verify
# 需要導入模塊: from testing import udir [as 別名]
# 或者: from testing.udir import udir [as 別名]
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
示例2: _verify
# 需要導入模塊: from testing import udir [as 別名]
# 或者: from testing.udir import udir [as 別名]
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
return module.lib
示例3: test_tmpdir
# 需要導入模塊: from testing import udir [as 別名]
# 或者: from testing.udir import udir [as 別名]
def test_tmpdir():
import tempfile, os
from testing.udir import udir
tmpdir = tempfile.mkdtemp(dir=str(udir))
ffi = FFI()
ffi.cdef("int foo(int);")
lib = ffi.verify("int foo(int a) { return a + 42; }", tmpdir=tmpdir)
assert os.listdir(tmpdir)
assert lib.foo(100) == 142
示例4: test_relative_to
# 需要導入模塊: from testing import udir [as 別名]
# 或者: from testing.udir import udir [as 別名]
def test_relative_to():
import tempfile, os
from testing.udir import udir
tmpdir = tempfile.mkdtemp(dir=str(udir))
ffi = FFI()
ffi.cdef("int foo(int);")
f = open(os.path.join(tmpdir, 'foo.h'), 'w')
f.write("int foo(int a) { return a + 42; }\n")
f.close()
lib = ffi.verify('#include "foo.h"',
include_dirs=['.'],
relative_to=os.path.join(tmpdir, 'x'))
assert lib.foo(100) == 142