Skip to content

Commit f55c712

Browse files
committed
Fix for introspection on windows
1 parent b632260 commit f55c712

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

tests/ndarray/test_dsl_kernels.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import subprocess
1010
import sys
11+
import tempfile
12+
import textwrap
13+
from pathlib import Path
1114

1215
import numpy as np
1316
import pytest
@@ -592,20 +595,30 @@ def test_dsl_kernel_float_cast_with_global_linear_idx_no_segfault_subprocess():
592595
if blosc2.IS_WASM:
593596
pytest.skip("subprocess is not supported on emscripten/wasm32")
594597

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+
"""
607614
)
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+
609622
assert result.returncode == 0, (
610623
"subprocess failed (possible segfault/regression in DSL float-cast path):\n"
611624
f"stdout:\n{result.stdout}\n"

0 commit comments

Comments
 (0)