| 1 | import pytest |
| 2 | from pathlib import Path |
| 3 | from . import support |
| 4 | |
| 5 | |
| 6 | def expand_template(template, name): |
| 7 | return support.DefaultExtensionTemplate(template, name).expand() |
| 8 | |
| 9 | |
| 10 | def test_expand_template(): |
| 11 | expanded = expand_template(""" |
| 12 | @EXPORT(f) |
| 13 | @EXPORT(g) |
| 14 | some more C stuff |
| 15 | @INIT |
| 16 | """, name='mytest') |
| 17 | defines_table = ['&f,', '&g,'] |
| 18 | defines = '\n '.join(defines_table) |
| 19 | init_code = support.DefaultExtensionTemplate.INIT_TEMPLATE % { |
| 20 | 'defines': defines, |
| 21 | 'legacy_methods': 'NULL', |
| 22 | 'name': 'mytest', |
| 23 | 'init_types': '', |
| 24 | 'globals_defs': '', |
| 25 | 'globals_field': '', |
| 26 | } |
| 27 | assert expanded.rstrip() == f"""#include <hpy.h> |
| 28 | |
| 29 | some more C stuff |
| 30 | {init_code} |
| 31 | """.rstrip() |
| 32 | |
| 33 | |
| 34 | TEST_DIR = Path(__file__).parent |
| 35 | |
| 36 | |
| 37 | def test_source_dump(tmpdir): |
| 38 | import pytest |
| 39 | test_file = 'test_00_basic' |
| 40 | parts = ['TestBasic', 'test_noop_function'] |
| 41 | rc = pytest.main(['--dump-dir=' + str(tmpdir), '::'.join([str(TEST_DIR.joinpath(test_file + ".py"))] + parts)]) |
| 42 | assert rc == 0 |
| 43 | expected_dir = '_'.join([test_file] + parts) |
| 44 | print("expected_dir = " + expected_dir) |
| 45 | test_dump_dir = None |
| 46 | for child in Path(tmpdir).iterdir(): |
| 47 | if expected_dir in str(child): |
| 48 | test_dump_dir = Path(child) |
| 49 | assert test_dump_dir and test_dump_dir.exists() |
| 50 | assert test_dump_dir.joinpath('mytest.c').exists() |