File: test_extmodules.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (73 lines) | stat: -rw-r--r-- 1,777 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
import pytest

from pypy.config.pypyoption import get_pypy_config
from pypy.objspace.std.objspace import StdObjSpace
from rpython.tool.udir import udir

mod_def = """
from pypy.interpreter.mixedmodule import MixedModule

import time

class Module(MixedModule):

    appleveldefs = {}

    interpleveldefs = {
    'clock'    : 'interp_time.clock',
    'time'     : 'interp_time.time_',
    'sleep'    : 'interp_time.sleep',
    }
"""

mod_interp = """
import time

from pypy.interpreter.gateway import unwrap_spec

def clock(space):
    return space.wrap(time.clock())

def time_(space):
    return space.wrap(time.time())

@unwrap_spec(seconds=float)
def sleep(space, seconds):
    '''sleep(seconds: float) -> None

    pause for a float number of seconds'''
    time.sleep(seconds)
"""

old_sys_path = []

def init_extmodule_code():
    pkg = udir.join("testext")
    pkg.ensure(dir=True)
    pkg.join("__init__.py").write("# package")
    mod = pkg.join("extmod")
    mod.ensure(dir=True)
    mod.join("__init__.py").write("#")
    mod.join("interp_time.py").write(mod_interp)
    mod.join("moduledef.py").write(mod_def)

class AppTestExtModules(object):
    def setup_class(cls):
        init_extmodule_code()
        conf = get_pypy_config()
        conf.objspace.extmodules = 'testext.extmod'
        old_sys_path[:] = sys.path[:]
        sys.path.insert(0, str(udir))
        space = StdObjSpace(conf)
        cls.space = space

    def teardown_class(cls):
        sys.path[:] = old_sys_path

    @pytest.mark.skipif("config.option.runappdirect")
    def test_import(self):
        import extmod
        assert not hasattr(extmod, '__file__')
        assert type(extmod.time()) is float
        assert extmod.sleep.__doc__.endswith('float number of seconds')