|
| 1 | +import pathlib |
| 2 | +import tempfile |
| 3 | +import textwrap |
| 4 | +import types |
| 5 | +import unittest |
| 6 | +from unittest import mock |
| 7 | + |
| 8 | +from pyperformance import compile as compile_mod |
| 9 | + |
| 10 | + |
| 11 | +class ParseConfigTests(unittest.TestCase): |
| 12 | + def test_parse_config_reads_tail_call_interp(self): |
| 13 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 14 | + root = pathlib.Path(tmpdir) |
| 15 | + config_path = root / "benchmark.conf" |
| 16 | + config_path.write_text( |
| 17 | + textwrap.dedent( |
| 18 | + f"""\ |
| 19 | + [config] |
| 20 | + json_dir = {root / "json"} |
| 21 | +
|
| 22 | + [scm] |
| 23 | + repo_dir = {root / "cpython"} |
| 24 | +
|
| 25 | + [compile] |
| 26 | + bench_dir = {root / "bench"} |
| 27 | + tail_call_interp = true |
| 28 | +
|
| 29 | + [run_benchmark] |
| 30 | + """ |
| 31 | + ), |
| 32 | + encoding="utf-8", |
| 33 | + ) |
| 34 | + |
| 35 | + conf = compile_mod.parse_config(str(config_path), "compile") |
| 36 | + |
| 37 | + self.assertTrue(conf.tail_call_interp) |
| 38 | + |
| 39 | + |
| 40 | +class CompileCommandTests(unittest.TestCase): |
| 41 | + def test_compile_adds_tail_call_interp_flag(self): |
| 42 | + conf = types.SimpleNamespace( |
| 43 | + build_dir="/tmp/build", |
| 44 | + repo_dir="/tmp/cpython", |
| 45 | + prefix="", |
| 46 | + debug=False, |
| 47 | + lto=False, |
| 48 | + pgo=True, |
| 49 | + jit="", |
| 50 | + tail_call_interp=True, |
| 51 | + pkg_only=[], |
| 52 | + jobs=0, |
| 53 | + ) |
| 54 | + app = types.SimpleNamespace( |
| 55 | + branch="main", |
| 56 | + logger=None, |
| 57 | + safe_makedirs=mock.Mock(), |
| 58 | + run=mock.Mock(), |
| 59 | + ) |
| 60 | + |
| 61 | + compile_mod.Python(app, conf).compile() |
| 62 | + |
| 63 | + configure_call = app.run.call_args_list[0] |
| 64 | + self.assertEqual( |
| 65 | + configure_call.args, |
| 66 | + ("/tmp/cpython/configure", "--with-tail-call-interp"), |
| 67 | + ) |
| 68 | + self.assertEqual(configure_call.kwargs, {"cwd": "/tmp/build"}) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + unittest.main() |
0 commit comments