PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/interpreter/test/test_extmodules.py

https://bitbucket.org/pypy/pypy/
Python | 68 lines | 63 code | 5 blank | 0 comment | 0 complexity | a76e0f4fad57418f3d2a0139700b421f MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. import sys
  2. import pytest
  3. from pypy.config.pypyoption import get_pypy_config
  4. from pypy.objspace.std import StdObjSpace
  5. from rpython.tool.udir import udir
  6. mod_init = """
  7. from pypy.interpreter.mixedmodule import MixedModule
  8. import time
  9. class Module(MixedModule):
  10. appleveldefs = {}
  11. interpleveldefs = {
  12. 'clock' : 'interp_time.clock',
  13. 'time' : 'interp_time.time_',
  14. 'sleep' : 'interp_time.sleep',
  15. }
  16. """
  17. mod_interp = """
  18. import time
  19. from pypy.interpreter.gateway import unwrap_spec
  20. def clock(space):
  21. return space.wrap(time.clock())
  22. def time_(space):
  23. return space.wrap(time.time())
  24. @unwrap_spec(seconds=float)
  25. def sleep(space, seconds):
  26. time.sleep(seconds)
  27. """
  28. old_sys_path = []
  29. def init_extmodule_code():
  30. pkg = udir.join("testext")
  31. pkg.ensure(dir=True)
  32. pkg.join("__init__.py").write("# package")
  33. mod = pkg.join("extmod")
  34. mod.ensure(dir=True)
  35. mod.join("__init__.py").write(mod_init)
  36. mod.join("interp_time.py").write(mod_interp)
  37. class AppTestExtModules(object):
  38. def setup_class(cls):
  39. init_extmodule_code()
  40. conf = get_pypy_config()
  41. conf.objspace.extmodules = 'testext.extmod'
  42. old_sys_path[:] = sys.path[:]
  43. sys.path.insert(0, str(udir))
  44. space = StdObjSpace(conf)
  45. cls.space = space
  46. def teardown_class(cls):
  47. sys.path[:] = old_sys_path
  48. @pytest.mark.skipif("config.option.runappdirect")
  49. def test_import(self):
  50. import extmod
  51. assert not hasattr(extmod, '__file__')
  52. assert type(extmod.time()) is float