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