本文整理汇总了Python中pypy.conftest.gettestobjspace函数的典型用法代码示例。如果您正苦于以下问题:Python gettestobjspace函数的具体用法?Python gettestobjspace怎么用?Python gettestobjspace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gettestobjspace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: make_class
def make_class(cls):
# XXX: this is (mostly) wrong: .compile() compiles the code object
# using the host python compiler, but then in the tests we load it
# with py.py. It works (mostly by chance) because the two functions
# are very simple and the bytecodes are compatible enough.
co = py.code.Source(
"""
def get_name():
return __name__
def get_file():
return __file__
"""
).compile()
if cls.compression == ZIP_DEFLATED:
space = gettestobjspace(usemodules=["zipimport", "zlib", "rctime", "struct"])
else:
space = gettestobjspace(usemodules=["zipimport", "rctime", "struct"])
cls.space = space
tmpdir = udir.ensure("zipimport_%s" % cls.__name__, dir=1)
now = time.time()
cls.w_now = space.wrap(now)
test_pyc = cls.make_pyc(space, co, now)
cls.w_test_pyc = space.wrap(test_pyc)
cls.w_compression = space.wrap(cls.compression)
cls.w_pathsep = space.wrap(cls.pathsep)
# ziptestmodule = tmpdir.ensure('ziptestmodule.zip').write(
ziptestmodule = tmpdir.join("somezip.zip")
cls.w_tmpzip = space.wrap(str(ziptestmodule))
cls.w_co = space.wrap(co)
cls.tmpdir = tmpdir
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:32,代码来源:test_zipimport.py
示例2: setup_class
def setup_class(cls):
# This imports support_test_sre as the global "s"
try:
cls.space = gettestobjspace(usemodules=('_locale',))
except py.test.skip.Exception:
cls.space = gettestobjspace(usemodules=('_rawffi',))
init_globals_hack(cls.space)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_app_sre.py
示例3: 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')
开发者ID:ieure,项目名称:pypy,代码行数:26,代码来源:test_posix2.py
示例4: setup_class
def setup_class(cls):
try:
cls.space = gettestobjspace(usemodules=('_locale',))
except Skipped:
cls.space = gettestobjspace(usemodules=('_rawffi',))
# This imports support_test_sre as the global "s"
init_globals_hack(cls.space)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_app_sre.py
示例5: test_hash_against_normal_tuple
def test_hash_against_normal_tuple(self):
N_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": False})
S_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})
def hash_test(values, must_be_specialized=True):
N_values_w = [N_space.wrap(value) for value in values]
S_values_w = [S_space.wrap(value) for value in values]
N_w_tuple = N_space.newtuple(N_values_w)
S_w_tuple = S_space.newtuple(S_values_w)
if must_be_specialized:
assert isinstance(S_w_tuple, W_SpecialisedTupleObject)
assert isinstance(N_w_tuple, W_TupleObject)
assert S_space.is_true(S_space.eq(N_w_tuple, S_w_tuple))
assert S_space.is_true(S_space.eq(N_space.hash(N_w_tuple), S_space.hash(S_w_tuple)))
hash_test([1,2])
hash_test([1.5,2.8])
hash_test([1.0,2.0])
hash_test(['arbitrary','strings'])
hash_test([1,(1,2,3,4)])
hash_test([1,(1,2)])
hash_test([1,('a',2)])
hash_test([1,()])
hash_test([1,2,3], must_be_specialized=False)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_specialisedtupleobject.py
示例6: test_abi_tag
def test_abi_tag(self):
space1 = gettestobjspace(soabi='TEST')
space2 = gettestobjspace(soabi='')
if sys.platform == 'win32':
assert importing.get_so_extension(space1) == '.TESTi.pyd'
assert importing.get_so_extension(space2) == '.pyd'
else:
assert importing.get_so_extension(space1) == '.TESTi.so'
assert importing.get_so_extension(space2) == '.so'
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_import.py
示例7: test_hash_agains_normal_tuple
def test_hash_agains_normal_tuple(self):
normalspace = gettestobjspace(**{"objspace.std.withsmalltuple": False})
w_tuple = normalspace.newtuple([self.space.wrap(1), self.space.wrap(2)])
smallspace = gettestobjspace(**{"objspace.std.withsmalltuple": True})
w_smalltuple = smallspace.newtuple([self.space.wrap(1), self.space.wrap(2)])
assert isinstance(w_smalltuple, W_SmallTupleObject)
assert isinstance(w_tuple, W_TupleObject)
assert not normalspace.is_true(normalspace.eq(w_tuple, w_smalltuple))
assert smallspace.is_true(smallspace.eq(w_tuple, w_smalltuple))
assert smallspace.is_true(smallspace.eq(normalspace.hash(w_tuple), smallspace.hash(w_smalltuple)))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:12,代码来源:test_smalltupleobject.py
示例8: setup_class
def setup_class(cls):
cls.space = gettestobjspace(usemodules=['cpyext', 'thread', '_rawffi'])
cls.space.getbuiltinmodule("cpyext")
from pypy.module.imp.importing import importhook
importhook(cls.space, "os") # warm up reference counts
state = cls.space.fromcache(RefcountState)
state.non_heaptypes_w[:] = []
开发者ID:ieure,项目名称:pypy,代码行数:7,代码来源:test_cpyext.py
示例9: setup_class
def setup_class(cls):
if option.runappdirect:
py.test.skip("Can't run this test with -A")
space = gettestobjspace(usemodules=('pypyjit',))
cls.space = space
w_f = space.appexec([], """():
def f():
pass
return f
""")
ll_code = cast_instance_to_base_ptr(w_f.code)
logger = Logger(MockSD())
oplist = parse("""
[i1, i2]
i3 = int_add(i1, i2)
guard_true(i3) []
""", namespace={'ptr0': 3}).operations
def interp_on_compile():
pypyjitdriver.on_compile(logger, LoopToken(), oplist, 'loop',
0, False, ll_code)
def interp_on_compile_bridge():
pypyjitdriver.on_compile_bridge(logger, LoopToken(), oplist, 0)
cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
开发者ID:pombredanne,项目名称:pypy,代码行数:28,代码来源:test_jit_hook.py
示例10: setup_class
def setup_class(cls):
cls.space = gettestobjspace(**{"objspace.std.withmapdict": True})
if option.runappdirect:
py.test.skip("can only be run on py.py")
def has_mapdict(space, w_inst):
return space.wrap(w_inst._get_mapdict_map() is not None)
cls.w_has_mapdict = cls.space.wrap(gateway.interp2app(has_mapdict))
开发者ID:yasirs,项目名称:pypy,代码行数:7,代码来源:test_classobj.py
示例11: setup_class
def setup_class(cls):
if sys.platform == "win32":
py.test.skip("select() doesn't work with pipes on win32")
space = gettestobjspace(usemodules=("select",))
cls.space = space
# Wraps a file descriptor in an socket-like object
cls.w_getpair = space.appexec(
[],
"""():
import os
class FileAsSocket:
def __init__(self, fd):
self.fd = fd
def fileno(self):
return self.fd
def send(self, data):
return os.write(self.fd, data)
def recv(self, length):
return os.read(self.fd, length)
def close(self):
return os.close(self.fd)
def getpair():
s1, s2 = os.pipe()
return FileAsSocket(s1), FileAsSocket(s2)
return getpair""",
)
开发者ID:alkorzt,项目名称:pypy,代码行数:27,代码来源:test_select.py
示例12: setup_class
def setup_class(cls):
space = gettestobjspace(usemodules=('_continuation', '_socket'))
cls.space = space
if option.runappdirect:
cls.w_lev = space.wrap(14)
else:
cls.w_lev = space.wrap(2)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_stackless_pickle.py
示例13: setup_class
def setup_class(cls):
from pypy.interpreter import gateway
cls.space = gettestobjspace(
**{"objspace.std.withmapdict": True,
"objspace.std.withmethodcachecounter": True,
"objspace.opcodes.CALL_METHOD": True})
#
def check(space, w_func, name):
w_code = space.getattr(w_func, space.wrap('func_code'))
nameindex = map(space.str_w, w_code.co_names_w).index(name)
entry = w_code._mapdict_caches[nameindex]
entry.failure_counter = 0
entry.success_counter = 0
INVALID_CACHE_ENTRY.failure_counter = 0
#
w_res = space.call_function(w_func)
assert space.eq_w(w_res, space.wrap(42))
#
entry = w_code._mapdict_caches[nameindex]
if entry is INVALID_CACHE_ENTRY:
failures = successes = 0
else:
failures = entry.failure_counter
successes = entry.success_counter
globalfailures = INVALID_CACHE_ENTRY.failure_counter
return space.wrap((failures, successes, globalfailures))
check.unwrap_spec = [gateway.ObjSpace, gateway.W_Root, str]
cls.w_check = cls.space.wrap(gateway.interp2app(check))
开发者ID:ieure,项目名称:pypy,代码行数:28,代码来源:test_mapdict.py
示例14: setup_class
def setup_class(cls):
space = gettestobjspace(usemodules=('_multiprocessing', 'thread', 'signal',
'struct', 'array'))
cls.space = space
cls.w_connections = space.newlist([])
def socketpair(space):
"A socket.socketpair() that works on Windows"
import socket, errno
serverSocket = socket.socket()
serverSocket.bind(('127.0.0.1', 0))
serverSocket.listen(1)
client = socket.socket()
client.setblocking(False)
try:
client.connect(('127.0.0.1', serverSocket.getsockname()[1]))
except socket.error, e:
assert e.args[0] in (errno.EINPROGRESS, errno.EWOULDBLOCK)
server, addr = serverSocket.accept()
# keep sockets alive during the test
space.call_method(cls.w_connections, "append", space.wrap(server))
space.call_method(cls.w_connections, "append", space.wrap(client))
return space.wrap((server.fileno(), client.fileno()))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:26,代码来源:test_connection.py
示例15: setup_class
def setup_class(cls):
cls.space = gettestobjspace(**{"objspace.std.withcelldict": True})
cls.w_impl_used = cls.space.appexec([], """():
import __pypy__
def impl_used(obj):
assert "ModuleDictImplementation" in __pypy__.internal_repr(obj)
return impl_used
""")
def is_in_cache(space, w_code, w_globals, w_name):
name = space.str_w(w_name)
cache = get_global_cache(space, w_code, w_globals)
index = [space.str_w(w_n) for w_n in w_code.co_names_w].index(name)
return space.wrap(cache[index].w_value is not None)
is_in_cache = gateway.interp2app(is_in_cache)
cls.w_is_in_cache = cls.space.wrap(is_in_cache)
stored_builtins = []
def rescue_builtins(space):
w_dict = space.builtin.getdict()
content = {}
for key, cell in w_dict.implementation.content.iteritems():
newcell = ModuleCell()
newcell.w_value = cell.w_value
content[key] = newcell
stored_builtins.append(content)
rescue_builtins = gateway.interp2app(rescue_builtins)
cls.w_rescue_builtins = cls.space.wrap(rescue_builtins)
def restore_builtins(space):
w_dict = space.builtin.getdict()
if not isinstance(w_dict.implementation, ModuleDictImplementation):
w_dict.implementation = ModuleDictImplementation(space)
w_dict.implementation.content = stored_builtins.pop()
restore_builtins = gateway.interp2app(restore_builtins)
cls.w_restore_builtins = cls.space.wrap(restore_builtins)
开发者ID:enyst,项目名称:plexnet,代码行数:33,代码来源:test_celldict.py
示例16: setup_class
def setup_class(cls):
space = gettestobjspace(usemodules=('bz2',))
cls.space = space
cls.w_TEXT = space.wrap(TEXT)
cls.w_DATA = space.wrap(DATA)
cls.w_decompress = space.wrap(decompress)
cls.w_HUGE_OK = space.wrap(HUGE_OK)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_bz2_compdecomp.py
示例17: setup_class
def setup_class(cls):
space = gettestobjspace(usemodules=("thread", "time"))
cls.space = space
if option.runappdirect:
def plain_waitfor(condition, delay=1):
adaptivedelay = 0.04
limit = time.time() + NORMAL_TIMEOUT * delay
while time.time() <= limit:
time.sleep(adaptivedelay)
gc.collect()
if condition():
return
adaptivedelay *= 1.05
print "*** timed out ***"
cls.w_waitfor = plain_waitfor
else:
cls.w_waitfor = space.wrap(interp2app_temp(waitfor))
cls.w_busywait = space.appexec(
[],
"""():
import time
return time.sleep
""",
)
开发者ID:alkorzt,项目名称:pypy,代码行数:27,代码来源:support.py
示例18: _prepare
def _prepare(self):
if hasattr(self, 'name2item'):
return
self.name2item = {}
space = gettestobjspace(usemodules=self.regrtest.usemodules)
if self.regrtest.dumbtest or self.regrtest.getoutputpath():
self.name2item['output'] = SimpleRunItem('output', self)
return
tup = start_intercept(space)
self.regrtest.run_file(space)
w_namemethods, w_doctestlist = collect_intercept(space, *tup)
# setup {name -> wrapped testcase method}
for w_item in space.unpackiterable(w_namemethods):
w_name, w_method = space.unpacktuple(w_item)
name = space.str_w(w_name)
testitem = AppTestCaseMethod(name, parent=self, w_method=w_method)
self.name2item[name] = testitem
# setup {name -> wrapped doctest module}
for w_item in space.unpackiterable(w_doctestlist):
w_name, w_module = space.unpacktuple(w_item)
name = space.str_w(w_name)
testitem = AppDocTestModule(name, parent=self, w_module=w_module)
self.name2item[name] = testitem
开发者ID:antoine1fr,项目名称:pygirl,代码行数:26,代码来源:conftest.py
示例19: test_pyc_magic_changes
def test_pyc_magic_changes(self):
# test that the pyc files produced by a space are not reimportable
# from another, if they differ in what opcodes they support
allspaces = [self.space]
for opcodename in self.space.config.objspace.opcodes.getpaths():
key = 'objspace.opcodes.' + opcodename
space2 = gettestobjspace(**{key: True})
allspaces.append(space2)
for space1 in allspaces:
for space2 in allspaces:
if space1 is space2:
continue
pathname = "whatever"
mtime = 12345
co = compile('x = 42', '?', 'exec')
cpathname = _testfile(importing.get_pyc_magic(space1),
mtime, co)
w_modulename = space2.wrap('somemodule')
stream = streamio.open_file_as_stream(cpathname, "rb")
try:
w_mod = space2.wrap(Module(space2, w_modulename))
magic = importing._r_long(stream)
timestamp = importing._r_long(stream)
space2.raises_w(space2.w_ImportError,
importing.load_compiled_module,
space2,
w_modulename,
w_mod,
cpathname,
magic,
timestamp,
stream.readall())
finally:
stream.close()
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:34,代码来源:test_import.py
示例20: setup_class
def setup_class(cls):
cls.space = space = gettestobjspace(usemodules=['_locale'])
if sys.platform != 'win32':
cls.w_language_en = cls.space.wrap("en_US")
cls.w_language_utf8 = cls.space.wrap("en_US.UTF-8")
cls.w_language_pl = cls.space.wrap("pl_PL.UTF-8")
cls.w_encoding_pl = cls.space.wrap("utf-8")
else:
cls.w_language_en = cls.space.wrap("English_US")
cls.w_language_utf8 = cls.space.wrap("English_US.65001")
cls.w_language_pl = cls.space.wrap("Polish_Poland.1257")
cls.w_encoding_pl = cls.space.wrap("cp1257")
import _locale
# check whether used locales are installed, otherwise the tests will
# fail
current = _locale.setlocale(_locale.LC_ALL)
try:
try:
_locale.setlocale(_locale.LC_ALL,
space.str_w(cls.w_language_en))
_locale.setlocale(_locale.LC_ALL,
space.str_w(cls.w_language_pl))
except _locale.Error:
py.test.skip("necessary locales not installed")
# Windows forbids the UTF-8 character set since Windows XP.
try:
_locale.setlocale(_locale.LC_ALL,
space.str_w(cls.w_language_utf8))
except _locale.Error:
del cls.w_language_utf8
finally:
_locale.setlocale(_locale.LC_ALL, current)
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:test_locale.py
注:本文中的pypy.conftest.gettestobjspace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论