def test_abi_tag(self): space1 = maketestobjspace(make_config(None, soabi='footest')) space2 = maketestobjspace(make_config(None, soabi='')) assert importing.get_so_extension(space1).startswith('.footest') if sys.platform == 'win32': assert importing.get_so_extension(space2) == '.pyd' else: assert importing.get_so_extension(space2) == '.so'
def test_abi_tag(self): space1 = maketestobjspace(make_config(None, soabi='TEST')) space2 = maketestobjspace(make_config(None, 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'
def test_abi_tag(self): space1 = maketestobjspace(make_config(None, soabi="TEST")) space2 = maketestobjspace(make_config(None, 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"
def test_pyc_magic_changes(self): # skipped: for now, PyPy generates only one kind of .pyc file # per version. Different versions should differ in # sys.implementation.cache_tag, which means that they'll look up # different .pyc files anyway. See test_get_tag() in test_app.py. py.test.skip("For now, PyPy generates only one kind of .pyc files") # 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 = maketestobjspace(make_config(None, **{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(space1, 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 = _r_long(stream) timestamp = _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()
def translates(self, func=None, argtypes=None, seeobj_w=[], **kwds): config = make_config(None, **kwds) if func is not None: if argtypes is None: nb_args = func.func_code.co_argcount argtypes = [W_Root] * nb_args # t = TranslationContext(config=config) self.t = t # for debugging ann = t.buildannotator() def _do_startup(): self.threadlocals.enter_thread(self) ann.build_types(_do_startup, [], complete_now=False) if func is not None: ann.build_types(func, argtypes, complete_now=False) if seeobj_w: def seeme(n): return seeobj_w[n] ann.build_types(seeme, [int], complete_now=False) # # annotate all _seen_extras, knowing that annotating some may # grow the list done = 0 while done < len(self._seen_extras): #print self._seen_extras ann.build_types(self._seen_extras[done], [], complete_now=False) ann.complete_pending_blocks() done += 1 ann.complete() assert done == len(self._seen_extras) #t.viewcg() t.buildrtyper().specialize() t.checkgraphs()
def translates(self, func=None, argtypes=None, **kwds): config = make_config(None, **kwds) if func is not None: if argtypes is None: nb_args = func.func_code.co_argcount argtypes = [W_Root] * nb_args # t = TranslationContext(config=config) self.t = t # for debugging ann = t.buildannotator() ann.policy.allow_someobjects = False if func is not None: ann.build_types(func, argtypes, complete_now=False) # # annotate all _seen_extras, knowing that annotating some may # grow the list done = 0 while done < len(self._seen_extras): #print self._seen_extras ann.build_types(self._seen_extras[done], [], complete_now=False) done += 1 ann.complete() #t.viewcg() t.buildrtyper().specialize() t.checkgraphs()
def translates(self, func=None, argtypes=None, seeobj_w=[], **kwds): config = make_config(None, **kwds) if func is not None: if argtypes is None: nb_args = func.func_code.co_argcount argtypes = [W_Root] * nb_args # t = TranslationContext(config=config) self.t = t # for debugging ann = t.buildannotator() def _do_startup(): self.threadlocals.enter_thread(self) W_SliceObject(w_some_obj(), w_some_obj(), w_some_obj()) ann.build_types(_do_startup, [], complete_now=False) if func is not None: ann.build_types(func, argtypes, complete_now=False) if seeobj_w: def seeme(n): return seeobj_w[n] ann.build_types(seeme, [int], complete_now=False) # # annotate all _seen_extras, knowing that annotating some may # grow the list done = 0 while done < len(self._seen_extras): #print self._seen_extras ann.build_types(self._seen_extras[done], [], complete_now=False) ann.complete_pending_blocks() done += 1 ann.complete() assert done == len(self._seen_extras) #t.viewcg() t.buildrtyper().specialize() t.checkgraphs()
def test_pyc_magic_changes(self): py.test.skip("For now, PyPy generates only one kind of .pyc files") # 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 = maketestobjspace(make_config(None, **{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()
def gettestobjspace(name=None, **kwds): """ helper for instantiating and caching space's for testing. """ try: config = make_config(option, objspace=name, **kwds) except ConflictConfigError, e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e))
def test_dont_reload_builtin_mods_on_startup(self): from pypy.tool.option import make_config, make_objspace config = make_config(None) space = make_objspace(config) w_executable = space.wrap('executable') assert space.str_w(space.getattr(space.sys, w_executable)) == 'py.py' space.setattr(space.sys, w_executable, space.wrap('foobar')) assert space.str_w(space.getattr(space.sys, w_executable)) == 'foobar' space.startup() assert space.str_w(space.getattr(space.sys, w_executable)) == 'foobar'
def test_dont_reload_builtin_mods_on_startup(self): from pypy.tool.option import make_config, make_objspace config = make_config(None) space = make_objspace(config) w_executable = space.wrap('executable') assert space.findattr(space.sys, w_executable) is None space.setattr(space.sys, w_executable, space.wrap('foobar')) assert space.str_w(space.getattr(space.sys, w_executable)) == 'foobar' space.startup() assert space.str_w(space.getattr(space.sys, w_executable)) == 'foobar'
def test_dont_reload_builtin_mods_on_startup(self): from pypy.tool.option import make_config, make_objspace config = make_config(None) space = make_objspace(config) w_executable = space.wrap("executable") assert space.findattr(space.sys, w_executable) is None space.setattr(space.sys, w_executable, space.wrap("foobar")) assert space.str_w(space.getattr(space.sys, w_executable)) == "foobar" space.startup() assert space.str_w(space.getattr(space.sys, w_executable)) == "foobar"
def maketestobjspace(config=None): if config is None: config = make_config(option) try: space = make_objspace(config) except OperationError, e: check_keyboard_interrupt(e) if option.verbose: import traceback traceback.print_exc() py.test.fail("fatal: cannot initialize objspace: %r" % (config.objspace.name, ))
def maketestobjspace(config=None): if config is None: config = make_config(option) try: space = make_objspace(config) except OperationError, e: check_keyboard_interrupt(e) if option.verbose: import traceback traceback.print_exc() py.test.fail("fatal: cannot initialize objspace: %r" % (config.objspace.name,))
def translates(self, func=None, argtypes=None, seeobj_w=[], extra_func=None, c_compile=False, **kwds): config = make_config(None, **kwds) if func is not None: if argtypes is None: nb_args = func.func_code.co_argcount argtypes = [W_Root] * nb_args # t = TranslationContext(config=config) self.t = t # for debugging ann = t.buildannotator() def entry_point(argv): self.threadlocals.enter_thread(self) W_SliceObject(w_some_obj(), w_some_obj(), w_some_obj()) if extra_func: extra_func(self) return 0 ann.build_types(entry_point, [s_list_of_strings], complete_now=False) if func is not None: ann.build_types(func, argtypes, complete_now=False) if seeobj_w: def seeme(n): return seeobj_w[n] ann.build_types(seeme, [int], complete_now=False) # # annotate all _seen_extras, knowing that annotating some may # grow the list done = 0 while done < len(self._seen_extras): #print self._seen_extras ann.build_types(self._seen_extras[done], [], complete_now=False) ann.complete_pending_blocks() done += 1 ann.complete() assert done == len(self._seen_extras) #t.viewcg() t.buildrtyper().specialize() t.checkgraphs() if c_compile: cbuilder = CStandaloneBuilder(t, entry_point, t.config) cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES) cbuilder.compile() return t, cbuilder
def maketestobjspace(config=None): if config is None: config = make_config(option) space = make_objspace(config) space.startup() # Initialize all builtin modules space.setitem(space.builtin.w_dict, space.wrap('AssertionError'), appsupport.build_pytest_assertion(space)) space.setitem(space.builtin.w_dict, space.wrap('raises'), space.wrap(appsupport.app_raises)) space.setitem(space.builtin.w_dict, space.wrap('skip'), space.wrap(appsupport.app_skip)) space.raises_w = appsupport.raises_w.__get__(space) return space
def test_flush_at_exit(): from pypy import conftest from pypy.tool.option import make_config, make_objspace from pypy.tool.udir import udir tmpfile = udir.join('test_flush_at_exit') config = make_config(conftest.option) space = make_objspace(config) space.appexec([space.wrap(str(tmpfile))], """(tmpfile): f = open(tmpfile, 'w') f.write('42') # no flush() and no close() import sys; sys._keepalivesomewhereobscure = f """) space.finish() assert tmpfile.read() == '42'
def test_flush_at_exit(): from pypy import conftest from pypy.tool.option import make_config, make_objspace from rpython.tool.udir import udir tmpfile = udir.join('test_flush_at_exit') config = make_config(conftest.option) space = make_objspace(config) space.appexec([space.wrap(str(tmpfile))], """(tmpfile): f = open(tmpfile, 'w') f.write('42') # no flush() and no close() import sys; sys._keepalivesomewhereobscure = f """) space.finish() assert tmpfile.read() == '42'
def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' space = make_objspace(config) space.startup() # Initialize all builtin modules space.setitem(space.builtin.w_dict, space.wrap('raises'), space.wrap(appsupport.app_raises)) space.setitem(space.builtin.w_dict, space.wrap('skip'), space.wrap(appsupport.app_skip)) space.setitem(space.builtin.w_dict, space.wrap('py3k_skip'), space.wrap(appsupport.app_py3k_skip)) space.raises_w = appsupport.raises_w.__get__(space) return space
def gettestobjspace(**kwds): """ helper for instantiating and caching space's for testing. """ try: config = make_config(option,**kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) key = config.getkey() try: return _SPACECACHE[key] except KeyError: if getattr(option, 'runappdirect', None): return TinyObjSpace(**kwds) space = maketestobjspace(config) _SPACECACHE[key] = space return space
def gettestobjspace(name=None, **kwds): """ helper for instantiating and caching space's for testing. """ config = make_config(option, objspace=name, **kwds) key = config.getkey() try: return _SPACECACHE[key] except KeyError: if option.runappdirect: if name not in (None, 'std'): myname = getattr(sys, 'pypy_objspaceclass', '') if not myname.lower().startswith(name): py.test.skip("cannot runappdirect test: " "%s objspace required" % (name,)) return TinyObjSpace(**kwds) space = maketestobjspace(config) _SPACECACHE[key] = space return space
def gettestobjspace(name=None, **kwds): """ helper for instantiating and caching space's for testing. """ config = make_config(option, objspace=name, **kwds) key = config.getkey() try: return _SPACECACHE[key] except KeyError: if option.runappdirect: if name not in (None, 'std'): myname = getattr(sys, 'pypy_objspaceclass', '') if not myname.lower().startswith(name): py.test.skip("cannot runappdirect test: " "%s objspace required" % (name, )) return TinyObjSpace(**kwds) space = maketestobjspace(config) _SPACECACHE[key] = space return space
def test_startup(self): config = make_config(None, usemodules=('_demo', )) space = make_objspace(config) w_modules = space.sys.get('modules') assert Module.demo_events == ['setup'] assert not space.contains_w(w_modules, space.wrap('_demo')) # first import w_import = space.builtin.get('__import__') w_demo = space.call(w_import, space.newlist([space.wrap('_demo')])) assert Module.demo_events == ['setup', 'startup'] # reload the module, this should not call startup again space.delitem(w_modules, space.wrap('_demo')) w_demo = space.call(w_import, space.newlist([space.wrap('_demo')])) assert Module.demo_events == ['setup', 'startup'] assert space.getattr(w_demo, space.wrap('measuretime'))
def test_flush_at_exit_IOError_and_ValueError(): from pypy import conftest from pypy.tool.option import make_config, make_objspace config = make_config(conftest.option) space = make_objspace(config) space.appexec([], """(): import io class MyStream(io.IOBase): def flush(self): raise IOError class MyStream2(io.IOBase): def flush(self): raise ValueError s = MyStream() s2 = MyStream2() import sys; sys._keepalivesomewhereobscure = s """) space.finish() # the IOError has been ignored
def test_startup(self): config = make_config(None, usemodules=('_demo',)) space = make_objspace(config) w_modules = space.sys.get('modules') assert _demo.Module.demo_events == ['setup'] assert not space.contains_w(w_modules, space.wrap('_demo')) # first import w_import = space.builtin.get('__import__') w_demo = space.call(w_import, space.newlist([space.wrap('_demo')])) assert _demo.Module.demo_events == ['setup', 'startup'] # reload the module, this should not call startup again space.delitem(w_modules, space.wrap('_demo')) w_demo = space.call(w_import, space.newlist([space.wrap('_demo')])) assert _demo.Module.demo_events == ['setup', 'startup'] assert space.getattr(w_demo, space.wrap('measuretime'))