本文整理汇总了Python中pypy.tool.udir.udir.join函数的典型用法代码示例。如果您正苦于以下问题:Python join函数的具体用法?Python join怎么用?Python join使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了join函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dont_inherit_across_import
def test_dont_inherit_across_import(self):
from pypy.tool.udir import udir
udir.join("test_dont_inherit_across_import.py").write("x = 1/2\n")
space = self.space
s1 = str(
py.code.Source(
"""
from __future__ import division
from test_dont_inherit_across_import import x
"""
)
)
w_result = space.appexec(
[space.wrap(str(udir)), space.wrap(s1)],
"""(udir, s1):
import sys
copy = sys.path[:]
sys.path.insert(0, udir)
try:
exec s1
finally:
sys.path[:] = copy
return x
""",
)
assert space.float_w(w_result) == 0
示例2: compile_shared_lib
def compile_shared_lib(self, outputfilename=None):
self = self.convert_sources_to_files()
if not self.separate_module_files:
if sys.platform != 'win32':
return self
if not self.export_symbols:
return self
basepath = udir.join('module_cache')
else:
#basepath = py.path.local(self.separate_module_files[0]).dirpath()
basepath = udir.join('shared_cache')
if outputfilename is None:
# find more or less unique name there
pth = basepath.join('externmod').new(ext=host.so_ext)
num = 0
while pth.check():
pth = basepath.join(
'externmod_%d' % (num,)).new(ext=host.so_ext)
num += 1
basepath.ensure(dir=1)
outputfilename = str(pth.dirpath().join(pth.purebasename))
lib = str(host.compile([], self, outputfilename=outputfilename,
standalone=False))
d = self._copy_attributes()
d['libraries'] += (lib,)
d['separate_module_files'] = ()
d['separate_module_sources'] = ()
return ExternalCompilationInfo(**d)
示例3: test_main_two
def test_main_two(self):
udir.ensure("js_two.py").write(py.code.Source("""
def f():
pass
"""))
self._test_not_raises(udir.join("js_two.py"), ["f"])
self._test_raises(udir.join("js_two.py"), [])
示例4: test_gcc_exec
def test_gcc_exec():
f = udir.join("x.c")
f.write("""
#include <stdio.h>
#include <test_gcc_exec.h>
int main()
{
printf("%d\\n", ANSWER);
return 0;
}
""")
dir1 = udir.join('test_gcc_exec_dir1').ensure(dir=1)
dir2 = udir.join('test_gcc_exec_dir2').ensure(dir=1)
dir1.join('test_gcc_exec.h').write('#define ANSWER 3\n')
dir2.join('test_gcc_exec.h').write('#define ANSWER 42\n')
eci = ExternalCompilationInfo(include_dirs=[str(dir1)])
# remove cache
path = cache_file_path([f], eci, 'build_executable_cache')
if path.check():
path.remove()
res = build_executable_cache([f], eci)
assert res == "3\n"
assert build_executable_cache([f], eci) == "3\n"
eci2 = ExternalCompilationInfo(include_dirs=[str(dir2)])
assert build_executable_cache([f], eci2) == "42\n"
f.write("#error BOOM\n")
err = py.test.raises(CompilationError, build_executable_cache, [f], eci2)
print '<<<'
print err
print '>>>'
示例5: test_gcc_ask
def test_gcc_ask():
f = udir.join("y.c")
f.write("""
#include <stdio.h>
#include <test_gcc_ask.h>
int main()
{
printf("hello\\n");
return 0;
}
""")
dir1 = udir.join('test_gcc_ask_dir1').ensure(dir=1)
dir2 = udir.join('test_gcc_ask_dir2').ensure(dir=1)
dir1.join('test_gcc_ask.h').write('/* hello world */\n')
dir2.join('test_gcc_ask.h').write('#error boom\n')
eci = ExternalCompilationInfo(include_dirs=[str(dir1)])
# remove cache
path = cache_file_path([f], eci, 'try_compile_cache')
if path.check():
path.remove()
assert try_compile_cache([f], eci)
assert try_compile_cache([f], eci)
assert build_executable_cache([f], eci) == "hello\n"
eci2 = ExternalCompilationInfo(include_dirs=[str(dir2)])
err = py.test.raises(CompilationError, try_compile_cache, [f], eci2)
print '<<<'
print err
print '>>>'
示例6: setup_module
def setup_module(mod):
if os.name != 'nt':
mod.space = gettestobjspace(usemodules=['posix', 'fcntl'])
else:
# On windows, os.popen uses the subprocess module
mod.space = gettestobjspace(usemodules=['posix', '_rawffi', 'thread'])
mod.path = udir.join('posixtestfile.txt')
mod.path.write("this is a test")
mod.path2 = udir.join('test_posix2-')
pdir = udir.ensure('posixtestdir', dir=True)
pdir.join('file1').write("test1")
os.chmod(str(pdir.join('file1')), 0600)
pdir.join('file2').write("test2")
pdir.join('another_longer_file_name').write("test3")
mod.pdir = pdir
unicode_dir = udir.ensure('fi\xc5\x9fier.txt', dir=True)
unicode_dir.join('somefile').write('who cares?')
mod.unicode_dir = unicode_dir
# in applevel tests, os.stat uses the CPython os.stat.
# Be sure to return times with full precision
# even when running on top of CPython 2.4.
os.stat_float_times(True)
# Initialize sys.filesystemencoding
space.call_method(space.getbuiltinmodule('sys'), 'getfilesystemencoding')
示例7: test_32bit_makefile
def test_32bit_makefile(self):
if platform.machine() != "i386":
py.test.skip("i386 only")
plat32 = Darwin_i386()
plat64 = Darwin_x86_64()
eci = ExternalCompilationInfo()
cfile_content = r"""
#include <stdio.h>
#include <limits.h>
int main() {
printf("%d\n", INT_MAX < LONG_MAX);
return 0;
}
"""
tmpdir = udir.join("32_makefile" + self.__class__.__name__).ensure(dir=1)
cfile = tmpdir.join("test_int_size.c")
cfile.write(cfile_content)
mk = plat32.gen_makefile([cfile], ExternalCompilationInfo(), path=tmpdir)
mk.write()
plat32.execute_makefile(mk)
res = plat32.execute(tmpdir.join("test_int_size"))
self.check_res(res, "0\n")
if host_factory == Darwin_x86_64:
tmpdir = udir.join("64_makefile" + self.__class__.__name__).ensure(dir=1)
cfile = tmpdir.join("test_int_size.c")
cfile.write(cfile_content)
mk = plat64.gen_makefile([cfile], ExternalCompilationInfo(), path=tmpdir)
mk.write()
plat64.execute_makefile(mk)
res = plat64.execute(tmpdir.join("test_int_size"))
self.check_res(res, "1\n")
示例8: setup_class
def setup_class(cls):
compiler = ccompiler.new_compiler()
c_file = udir.join('rffilib.c')
c_file.write(c_source)
compiler.compile([str(c_file)], output_dir='/')
compiler.link_shared_lib([str(udir.join('rffilib.o'))],
'rffi', output_dir=str(udir))
cls.lib = ctypes.CDLL(str(udir.join('librffi.so')))
示例9: setup_module
def setup_module(mod):
mod.space = gettestobjspace(usemodules=['posix'])
mod.path = udir.join('posixtestfile.txt')
mod.path.write("this is a test")
mod.path2 = udir.join('posixtestlargefile')
pdir = udir.ensure('posixtestdir', dir=True)
pdir.join('file1').write("test1")
os.chmod(str(pdir.join('file1')), 0600)
pdir.join('file2').write("test2")
pdir.join('another_longer_file_name').write("test3")
mod.pdir = pdir
示例10: setup_class
def setup_class(cls):
testfn.write(testcode, 'w')
udir.join(testmodule + '.py').write(testmodulecode, 'w')
udir.ensure(testpackage, '__init__.py')
udir.join(testpackage, testmodule + '.py').write(testmodulecode, 'w')
space = cls.space
cls.w_oldsyspath = space.appexec([space.wrap(str(udir))], """(udir):
import sys
old = sys.path[:]
sys.path.insert(0, udir)
return old
""")
示例11: rundemo
def rundemo(entrypoint, *args):
view = conftest.option.view
seed = demo_conftest.option.randomseed
benchmark = bench_conftest.option.benchmark
logfile = str(udir.join('%s.log' % (entrypoint.__name__,)))
try:
os.unlink(logfile)
except OSError:
pass
os.environ['PYPYJITLOG'] = logfile
if benchmark:
py.test.skip("benchmarking: working in progress")
arglist = ', '.join(['a%d' % i for i in range(len(args))])
miniglobals = {'Benchmark': bench_conftest.Benchmark,
'original_entrypoint': entrypoint}
exec py.code.Source("""
def benchmark_runner(%s):
bench = Benchmark()
while 1:
res = original_entrypoint(%s)
if bench.stop():
break
return res
""" % (arglist, arglist)).compile() in miniglobals
entrypoint = miniglobals['benchmark_runner']
nb_args = len(args) # XXX ints only for now
if machine_code_dumper:
machine_code_dumper._freeze_() # clean up state
rgenop = RGenOp()
gv_entrypoint = rcompile(rgenop, entrypoint, [int]*nb_args,
random_seed=seed)
if machine_code_dumper:
machine_code_dumper._freeze_() # clean up state
print
print 'Random seed value: %d' % (seed,)
print
print 'Running %s(%s)...' % (entrypoint.__name__,
', '.join(map(repr, args)))
expected = entrypoint(*args)
print 'Python ===>', expected
F1 = lltype.FuncType([lltype.Signed] * nb_args, lltype.Signed)
fp = RGenOp.get_python_callable(lltype.Ptr(F1), gv_entrypoint)
res = runfp(fp, *args)
print '%-6s ===>' % RGenOp.__name__, res
print
if res != expected:
raise AssertionError(
"expected return value is %s, got %s\nseed = %s" % (
expected, res, seed))
if view and machine_code_dumper:
from pypy.jit.codegen.i386.viewcode import World
world = World()
world.parse(open(logfile))
world.show()
示例12: eating_callback
def eating_callback(self):
h_source = py.code.Source("""
#ifndef _CALLBACK_H
#define _CALLBACK_H
extern Signed eating_callback(Signed arg, Signed(*call)(Signed));
#endif /* _CALLBACK_H */
""")
h_include = udir.join('callback.h')
h_include.write(h_source)
c_source = py.code.Source("""
Signed eating_callback(Signed arg, Signed(*call)(Signed))
{
Signed res = call(arg);
if (res == -1)
return -1;
return res;
}
""")
eci = ExternalCompilationInfo(includes=['callback.h'],
include_dirs=[str(udir)],
separate_module_sources=[c_source],
export_symbols=['eating_callback'])
args = [SIGNED, CCallback([SIGNED], SIGNED)]
eating_callback = llexternal('eating_callback', args, SIGNED,
compilation_info=eci)
return eating_callback
示例13: return_char
def return_char(self, signed):
ctype_pref = ["un", ""][signed]
rffi_type = [UCHAR, SIGNEDCHAR][signed]
h_source = py.code.Source("""
%ssigned char returnchar(void)
{
return 42;
}
""" % (ctype_pref, ))
h_file = udir.join("opaque2%s.h" % (ctype_pref, ))
h_file.write(h_source)
from pypy.rpython.tool import rffi_platform
eci = ExternalCompilationInfo(
includes=[h_file.basename],
include_dirs=[str(udir)]
)
ll_returnchar = llexternal('returnchar', [], rffi_type, compilation_info=eci)
def f():
result = ll_returnchar()
return result
f1 = self.compile(f, [])
assert f1() == chr(42)
示例14: test_prebuilt_constant
def test_prebuilt_constant(self):
py.test.skip("Think how to do it sane")
h_source = py.code.Source("""
int x = 3;
char** z = NULL;
#endif
""")
h_include = udir.join('constants.h')
h_include.write(h_source)
eci = ExternalCompilationInfo(includes=['stdio.h',
str(h_include.basename)],
include_dirs=[str(udir)])
get_x, set_x = CExternVariable(lltype.Signed, 'x', eci)
get_z, set_z = CExternVariable(CCHARPP, 'z', eci)
def f():
one = get_x()
set_x(13)
return one + get_x()
def g():
l = liststr2charpp(["a", "b", "c"])
try:
set_z(l)
return charp2str(get_z()[2])
finally:
free_charpp(l)
fn = self.compile(f, [])
assert fn() == 16
gn = self.compile(g, [])
assert gn() == "c"
示例15: convert_sources_to_files
def convert_sources_to_files(self, cache_dir=None, being_main=False):
if not self.separate_module_sources:
return self
if cache_dir is None:
cache_dir = udir.join('module_cache').ensure(dir=1)
num = 0
files = []
for source in self.separate_module_sources:
while 1:
filename = cache_dir.join('module_%d.c' % num)
num += 1
if not filename.check():
break
f = filename.open("w")
if being_main:
f.write("#define PYPY_NOT_MAIN_FILE\n")
if sys.platform == 'win32':
f.write("#define WIN32_LEAN_AND_MEAN\n")
self.write_c_header(f)
source = str(source)
f.write(source)
if not source.endswith('\n'):
f.write('\n')
f.close()
files.append(str(filename))
d = self._copy_attributes()
d['separate_module_sources'] = ()
d['separate_module_files'] += tuple(files)
return ExternalCompilationInfo(**d)