本文整理汇总了Python中testing.udir.udir.join函数的典型用法代码示例。如果您正苦于以下问题:Python join函数的具体用法?Python join怎么用?Python join使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了join函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_class
def setup_class(cls):
from testing.udir import udir
udir.join('testownlib.c').write(SOURCE)
subprocess.check_call(
'gcc testownlib.c -shared -fPIC -o testownlib.so',
cwd=str(udir), shell=True)
cls.module = str(udir.join('testownlib.so'))
示例2: test_verifier_args
def test_verifier_args(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!4*/#include "test_verifier_args.h"\n' % self
udir.join('test_verifier_args.h').write('#include <math.h>\n')
v = Verifier(ffi, csrc, include_dirs=[str(udir)],
force_generic_engine=self.generic)
library = v.load_library()
assert library.sin(12.3) == math.sin(12.3)
示例3: really_run_setup_and_program
def really_run_setup_and_program(dirname, venv_dir_and_paths, python_snippet):
venv_dir, paths = venv_dir_and_paths
def remove(dir):
dir = str(SNIPPET_DIR.join(dirname, dir))
shutil.rmtree(dir, ignore_errors=True)
remove('build')
remove('__pycache__')
for basedir in os.listdir(str(SNIPPET_DIR.join(dirname))):
remove(os.path.join(basedir, '__pycache__'))
olddir = os.getcwd()
python_f = udir.join('x.py')
python_f.write(py.code.Source(python_snippet))
try:
os.chdir(str(SNIPPET_DIR.join(dirname)))
if os.name == 'nt':
bindir = 'Scripts'
else:
bindir = 'bin'
vp = str(venv_dir.join(bindir).join('python'))
env = os.environ.copy()
env['PYTHONPATH'] = paths
subprocess.check_call((vp, 'setup.py', 'clean'), env=env)
subprocess.check_call((vp, 'setup.py', 'install'), env=env)
subprocess.check_call((vp, str(python_f)), env=env)
finally:
os.chdir(olddir)
示例4: create_venv
def create_venv(name):
tmpdir = udir.join(name)
try:
subprocess.check_call(['virtualenv', '--distribute',
'-p', os.path.abspath(sys.executable),
str(tmpdir)])
except OSError as e:
py.test.skip("Cannot execute virtualenv: %s" % (e,))
site_packages = None
for dirpath, dirnames, filenames in os.walk(str(tmpdir)):
if os.path.basename(dirpath) == 'site-packages':
site_packages = dirpath
break
if site_packages:
try:
from cffi import _pycparser
modules = ('cffi', '_cffi_backend')
except ImportError:
modules = ('cffi', '_cffi_backend', 'pycparser')
try:
import ply
except ImportError:
pass
else:
modules += ('ply',) # needed for older versions of pycparser
for module in modules:
target = imp.find_module(module)[1]
os.symlink(target, os.path.join(site_packages,
os.path.basename(target)))
return tmpdir
示例5: test_invalid_dotdotdot_in_macro
def test_invalid_dotdotdot_in_macro():
ffi = FFI()
ffi.cdef("#define FOO ...")
target = udir.join('test_invalid_dotdotdot_in_macro.py')
e = py.test.raises(VerificationError, make_py_source, ffi,
'test_invalid_dotdotdot_in_macro', str(target))
assert str(e.value) == ("macro FOO: cannot use the syntax '...' in "
"'#define FOO ...' when using the ABI mode")
示例6: test_no_cross_include
def test_no_cross_include():
baseffi = FFI()
baseffi.set_source('test_no_cross_include_base', "..source..")
#
ffi = FFI()
ffi.include(baseffi)
target = udir.join('test_no_cross_include.py')
py.test.raises(VerificationError, make_py_source,
ffi, 'test_no_cross_include', str(target))
示例7: setup_method
def setup_method(self, meth):
self.executable = os.path.abspath(sys.executable)
self.rootdir = os.path.abspath(os.path.dirname(os.path.dirname(
cffi.__file__)))
self.udir = udir.join(meth.__name__)
os.mkdir(str(self.udir))
if meth.chdir_to_tmp:
self.saved_cwd = os.getcwd()
os.chdir(str(self.udir))
示例8: setup_module
def setup_module(mod):
SRC = """
#include <string.h>
#define FOOBAR (-42)
static const int FOOBAZ = -43;
#define BIGPOS 420000000000L
#define BIGNEG -420000000000L
int add42(int x) { return x + 42; }
int add43(int x, ...) { return x; }
int globalvar42 = 1234;
const int globalconst42 = 4321;
const char *const globalconsthello = "hello";
struct foo_s;
typedef struct bar_s { int x; signed char a[]; } bar_t;
enum foo_e { AA, BB, CC };
void init_test_re_python(void) { } /* windows hack */
void PyInit__test_re_python(void) { } /* windows hack */
"""
tmpdir = udir.join('test_re_python')
tmpdir.ensure(dir=1)
c_file = tmpdir.join('_test_re_python.c')
c_file.write(SRC)
ext = ffiplatform.get_extension(
str(c_file),
'_test_re_python',
export_symbols=['add42', 'add43', 'globalvar42',
'globalconst42', 'globalconsthello']
)
outputfilename = ffiplatform.compile(str(tmpdir), ext)
mod.extmod = outputfilename
mod.tmpdir = tmpdir
#
ffi = FFI()
ffi.cdef("""
#define FOOBAR -42
static const int FOOBAZ = -43;
#define BIGPOS 420000000000L
#define BIGNEG -420000000000L
int add42(int);
int add43(int, ...);
int globalvar42;
const int globalconst42;
const char *const globalconsthello = "hello";
int no_such_function(int);
int no_such_globalvar;
struct foo_s;
typedef struct bar_s { int x; signed char a[]; } bar_t;
enum foo_e { AA, BB, CC };
int strlen(const char *);
""")
ffi.set_source('re_python_pysrc', None)
ffi.emit_python_code(str(tmpdir.join('re_python_pysrc.py')))
mod.original_ffi = ffi
#
sys.path.insert(0, str(tmpdir))
示例9: test_struct_included
def test_struct_included():
baseffi = FFI()
baseffi.cdef("struct foo_s { int x; };")
baseffi.set_source('test_struct_included_base', None)
#
ffi = FFI()
ffi.include(baseffi)
target = udir.join('test_struct_included.py')
make_py_source(ffi, 'test_struct_included', str(target))
assert target.read() == r"""# auto-generated file
示例10: test_constant_of_value_unknown_to_the_compiler
def test_constant_of_value_unknown_to_the_compiler():
extra_c_source = udir.join(
'extra_test_constant_of_value_unknown_to_the_compiler.c')
extra_c_source.write('const int external_foo = 42;\n')
ffi = FFI()
ffi.cdef("const int external_foo;")
lib = verify(ffi, 'test_constant_of_value_unknown_to_the_compiler', """
extern const int external_foo;
""", sources=[str(extra_c_source)])
assert lib.external_foo == 42
示例11: test_write_source_explicit_filename
def test_write_source_explicit_filename(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic)
v.sourcefilename = filename = str(udir.join('write_source.c'))
v.write_source()
assert filename == v.sourcefilename
with open(filename, 'r') as f:
data = f.read()
assert csrc in data
示例12: test_include
def test_include():
ffi = FFI()
ffi.cdef("#define ABC 123")
ffi.set_source('test_include', None)
target = udir.join('test_include.py')
make_py_source(ffi, 'test_include', str(target))
assert target.read() == r"""# auto-generated file
import _cffi_backend
ffi = _cffi_backend.FFI('test_include',
_version = 0x2601,
_types = b'',
_globals = (b'\xFF\xFF\xFF\x1FABC',123,),
)
"""
#
ffi2 = FFI()
ffi2.include(ffi)
target2 = udir.join('test2_include.py')
make_py_source(ffi2, 'test2_include', str(target2))
assert target2.read() == r"""# auto-generated file
示例13: setup_class
def setup_class(cls):
cls.module = None
from testing.udir import udir
udir.join('testownlib.c').write(SOURCE)
if sys.platform == 'win32':
import os
# did we already build it?
if os.path.exists(str(udir.join('testownlib.dll'))):
cls.module = str(udir.join('testownlib.dll'))
return
# try (not too hard) to find the version used to compile this python
# no mingw
from distutils.msvc9compiler import get_build_version
version = get_build_version()
toolskey = "VS%0.f0COMNTOOLS" % version
toolsdir = os.environ.get(toolskey, None)
if toolsdir is None:
return
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
productdir = os.path.abspath(productdir)
vcvarsall = os.path.join(productdir, "vcvarsall.bat")
# 64?
arch = 'x86'
if sys.maxsize > 2**32:
arch = 'amd64'
if os.path.isfile(vcvarsall):
cmd = '"%s" %s' % (vcvarsall, arch) + ' & cl.exe testownlib.c ' \
' /LD /Fetestownlib.dll'
subprocess.check_call(cmd, cwd = str(udir), shell=True)
cls.module = str(udir.join('testownlib.dll'))
else:
subprocess.check_call(
'cc testownlib.c -shared -fPIC -o testownlib.so',
cwd=str(udir), shell=True)
cls.module = str(udir.join('testownlib.so'))
示例14: test_compile_module_explicit_filename
def test_compile_module_explicit_filename(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!2*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic)
basename = self.__class__.__name__ + 'test_compile_module'
v.modulefilename = filename = str(udir.join(basename + '.so'))
v.compile_module()
assert filename == v.modulefilename
assert v.get_module_name() == basename
if v.generates_python_module():
mod = imp.load_dynamic(v.get_module_name(), v.modulefilename)
assert hasattr(mod, '_cffi_setup')
示例15: create_venv
def create_venv(name):
tmpdir = udir.join(name)
try:
subprocess.check_call(['virtualenv', '--distribute',
'-p', os.path.abspath(sys.executable),
str(tmpdir)])
except OSError as e:
py.test.skip("Cannot execute virtualenv: %s" % (e,))
try:
deepcopy = os.symlink
except:
import shutil, errno
def deepcopy(src, dst):
try:
shutil.copytree(src, dst)
except OSError as e:
if e.errno in (errno.ENOTDIR, errno.EINVAL):
shutil.copy(src, dst)
else:
print('got errno')
print(e.errno)
print('not')
print(errno.ENOTDIR)
raise
site_packages = None
for dirpath, dirnames, filenames in os.walk(str(tmpdir)):
if os.path.basename(dirpath) == 'site-packages':
site_packages = dirpath
break
if site_packages:
try:
from cffi import _pycparser
modules = ('cffi', '_cffi_backend')
except ImportError:
modules = ('cffi', '_cffi_backend', 'pycparser')
try:
import ply
except ImportError:
pass
else:
modules += ('ply',) # needed for older versions of pycparser
for module in modules:
target = imp.find_module(module)[1]
deepcopy(target, os.path.join(site_packages,
os.path.basename(target)))
return tmpdir