| 1 |
""" |
| 2 |
In this file we check that if we use legacy features in universal mode, we |
| 3 |
get the expected compile time errors |
| 4 |
""" |
| 5 |
|
| 6 |
from .support import HPyTest, make_hpy_abi_fixture, ONLY_LINUX |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
ONLY_GCC = ONLY_LINUX |
| 16 |
|
| 17 |
|
| 18 |
class TestLegacyForbidden(HPyTest): |
| 19 |
|
| 20 |
hpy_abi = make_hpy_abi_fixture(['universal'], class_fixture=True) |
| 21 |
|
| 22 |
LEGACY_ERROR = "Cannot use legacy functions when targeting the HPy Universal ABI" |
| 23 |
|
| 24 |
def test_expect_make_error(self): |
| 25 |
src = """ |
| 26 |
#error "this is a compile time error" |
| 27 |
""" |
| 28 |
self.expect_make_error(src, "this is a compile time error") |
| 29 |
|
| 30 |
def test_Python_h_forbidden(self, capfd): |
| 31 |
src = """ |
| 32 |
#include <Python.h> |
| 33 |
@INIT |
| 34 |
""" |
| 35 |
self.expect_make_error(src, |
| 36 |
"It is forbidden to #include <Python.h> " |
| 37 |
"when targeting the HPy Universal ABI") |
| 38 |
|
| 39 |
@ONLY_GCC |
| 40 |
def test_HPy_AsPyObject(self, capfd): |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
src = """ |
| 46 |
HPyDef_METH(f, "f", HPyFunc_NOARGS) |
| 47 |
static HPy f_impl(HPyContext *ctx, HPy self) |
| 48 |
{ |
| 49 |
cpy_PyObject *pyobj = HPy_AsPyObject(ctx, self); |
| 50 |
(void)pyobj; // silence the warning about unused variable |
| 51 |
return HPy_NULL; |
| 52 |
} |
| 53 |
@EXPORT(f) |
| 54 |
@INIT |
| 55 |
""" |
| 56 |
self.expect_make_error(src, self.LEGACY_ERROR) |
| 57 |
|
| 58 |
@ONLY_GCC |
| 59 |
def test_HPy_FromPyObject(self, capfd): |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
src = """ |
| 65 |
HPyDef_METH(f, "f", HPyFunc_NOARGS) |
| 66 |
static HPy f_impl(HPyContext *ctx, HPy self) |
| 67 |
{ |
| 68 |
cpy_PyObject *pyobj = NULL; |
| 69 |
return HPy_FromPyObject(ctx, pyobj); |
| 70 |
} |
| 71 |
@EXPORT(f) |
| 72 |
@INIT |
| 73 |
""" |
| 74 |
self.expect_make_error(src, self.LEGACY_ERROR) |