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[:] = []
def setup_class(cls): # following from AppTestCpythonExtensionBase, with cppyy added cls.space = gettestobjspace(usemodules=['cpyext', 'cppyy', 'thread', '_rawffi', '_ffi', 'array']) cls.space.getbuiltinmodule("cpyext") from pypy.module.imp.importing import importhook importhook(cls.space, "os") # warm up reference counts from pypy.module.cpyext.pyobject import RefcountState state = cls.space.fromcache(RefcountState) state.non_heaptypes_w[:] = [] # cppyy specific additions (not that the test_dct is loaded late # to allow the generated extension module be loaded first) cls.w_test_dct = cls.space.wrap(test_dct) cls.w_datatypes = cls.space.appexec([], """(): import cppyy, cpyext""")
def test_lock(self, space, monkeypatch): from pypy.module.imp.importing import getimportlock, importhook # Force importing the module _file now space.builtin.get('file') # Monkeypatch the import lock and add a counter importlock = getimportlock(space) original_acquire = importlock.acquire_lock def acquire_lock(): importlock.count += 1 original_acquire() importlock.count = 0 monkeypatch.setattr(importlock, 'acquire_lock', acquire_lock) # An already imported module importhook(space, 'sys') assert importlock.count == 0 # A new module importhook(space, 're') assert importlock.count == 9 # Import it again previous_count = importlock.count importhook(space, 're') assert importlock.count == previous_count
def test_lock(self, space, monkeypatch): from pypy.module.imp.importing import getimportlock, importhook # Force importing the module _file now space.builtin.get('file') # Monkeypatch the import lock and add a counter importlock = getimportlock(space) original_acquire = importlock.acquire_lock def acquire_lock(): importlock.count += 1 original_acquire() importlock.count = 0 monkeypatch.setattr(importlock, 'acquire_lock', acquire_lock) # An already imported module importhook(space, 'sys') assert importlock.count == 0 # A new module importhook(space, 're') assert importlock.count == 7 # Import it again previous_count = importlock.count importhook(space, 're') assert importlock.count == previous_count
def test_lock(self, space, monkeypatch): from pypy.module.imp.importing import getimportlock, importhook # Monkeypatch the import lock and add a counter importlock = getimportlock(space) original_acquire = importlock.acquire_lock def acquire_lock(): importlock.count += 1 original_acquire() importlock.count = 0 monkeypatch.setattr(importlock, 'acquire_lock', acquire_lock) # An already imported module importhook(space, 'sys') assert importlock.count == 0 # A new module importhook(space, '__future__') assert importlock.count == 1 # Import it again previous_count = importlock.count importhook(space, '__future__') assert importlock.count == previous_count
def setup_class(cls): 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[:] = []
def startup(self, space): from pypy.module.posix import interp_posix from pypy.module.imp import importing interp_posix.get(space).startup(space) # Import structseq before the full importlib is ready importing.importhook(space, '_structseq')
def setup_class(cls): cls.space.getbuiltinmodule("cpyext") from pypy.module.imp.importing import importhook importhook(cls.space, "os") # warm up reference counts