Debian Codegraph @

extra_tests/hpy_tests/_vendored/test_hpyimport.py

raw symbols SCIP
1 from .support import HPyTest
2
3 class TestImport(HPyTest):
4
5 def test_ImportModule(self):
6 import pytest
7 import sys
8 mod = self.make_module("""
9 HPyDef_METH(f, "f", HPyFunc_O)
10 static HPy f_impl(HPyContext *ctx, HPy self, HPy h_name)
11 {
12 // we use bytes because ATM we don't have HPyUnicode_AsUTF8 or similar
13 const char *name = HPyBytes_AsString(ctx, h_name);
14 if (name == NULL)
15 return HPy_NULL;
16 return HPyImport_ImportModule(ctx, name);
17 }
18 @EXPORT(f)
19 @INIT
20 """)
21 sys2 = mod.f(b'sys')
22 assert sys is sys2
23 with pytest.raises(ImportError):
24 mod.f(b'This is the name of a module which does not exist, hopefully')