本文整理汇总了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