|
8 | 8 |
|
9 | 9 | import subprocess |
10 | 10 | import sys |
| 11 | +import tempfile |
| 12 | +import textwrap |
| 13 | +from pathlib import Path |
11 | 14 |
|
12 | 15 | import numpy as np |
13 | 16 | import pytest |
@@ -592,20 +595,30 @@ def test_dsl_kernel_float_cast_with_global_linear_idx_no_segfault_subprocess(): |
592 | 595 | if blosc2.IS_WASM: |
593 | 596 | pytest.skip("subprocess is not supported on emscripten/wasm32") |
594 | 597 |
|
595 | | - code = ( |
596 | | - "import numpy as np\n" |
597 | | - "import blosc2\n" |
598 | | - "@blosc2.dsl_kernel\n" |
599 | | - "def kernel(start, stop, nitems):\n" |
600 | | - " step = (float(stop) - float(start)) / float(nitems)\n" |
601 | | - " return float(start) + _global_linear_idx * step # noqa: F821\n" |
602 | | - "shape = (10, 100)\n" |
603 | | - "arr = blosc2.lazyudf(kernel, (-10, 10, 999), dtype=np.float32, shape=shape).compute()\n" |
604 | | - "exp = np.linspace(-10, 10, np.prod(shape), dtype=np.float32).reshape(shape)\n" |
605 | | - "np.testing.assert_allclose(arr, exp, rtol=1e-6, atol=1e-6)\n" |
606 | | - "print('ok')\n" |
| 598 | + code = textwrap.dedent( |
| 599 | + """ |
| 600 | + import numpy as np |
| 601 | + import blosc2 |
| 602 | +
|
| 603 | + @blosc2.dsl_kernel |
| 604 | + def kernel(start, stop, nitems): |
| 605 | + step = (float(stop) - float(start)) / float(nitems) |
| 606 | + return float(start) + _global_linear_idx * step # noqa: F821 |
| 607 | +
|
| 608 | + shape = (10, 100) |
| 609 | + arr = blosc2.lazyudf(kernel, (-10, 10, 999), dtype=np.float32, shape=shape).compute() |
| 610 | + exp = np.linspace(-10, 10, np.prod(shape), dtype=np.float32).reshape(shape) |
| 611 | + np.testing.assert_allclose(arr, exp, rtol=1e-6, atol=1e-6) |
| 612 | + print("ok") |
| 613 | + """ |
607 | 614 | ) |
608 | | - result = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True, check=False) |
| 615 | + |
| 616 | + # Run from a real .py file so inspect.getsource() can recover the DSL source. |
| 617 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 618 | + script = Path(tmpdir) / "dsl_kernel_subprocess.py" |
| 619 | + script.write_text(code, encoding="utf-8") |
| 620 | + result = subprocess.run([sys.executable, str(script)], capture_output=True, text=True, check=False) |
| 621 | + |
609 | 622 | assert result.returncode == 0, ( |
610 | 623 | "subprocess failed (possible segfault/regression in DSL float-cast path):\n" |
611 | 624 | f"stdout:\n{result.stdout}\n" |
|
0 commit comments