forked from hpyproject/hpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_hpyglobal.py
38 lines (31 loc) · 1.14 KB
/
test_hpyglobal.py
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
"""
NOTE: this tests are also meant to be run as PyPy "applevel" tests.
This means that global imports will NOT be visible inside the test
functions. In particular, you have to "import pytest" inside the test in order
to be able to use e.g. pytest.raises (which on PyPy will be implemented by a
"fake pytest module")
"""
from .support import HPyTest
class TestHPyGlobal(HPyTest):
def test_basics(self):
mod = self.make_module("""
HPyGlobal myglobal;
HPyDef_METH(setg, "setg", setg_impl, HPyFunc_O)
static HPy setg_impl(HPyContext *ctx, HPy self, HPy arg)
{
HPyGlobal_Store(ctx, &myglobal, arg);
return HPy_Dup(ctx, ctx->h_None);
}
HPyDef_METH(getg, "getg", getg_impl, HPyFunc_NOARGS)
static HPy getg_impl(HPyContext *ctx, HPy self)
{
return HPyGlobal_Load(ctx, myglobal);
}
@EXPORT(setg)
@EXPORT(getg)
@EXPORT_GLOBAL(myglobal)
@INIT
""")
obj = {'hello': 'world'}
assert mod.setg(obj) is None
assert mod.getg() is obj