Skip to content

Commit 9b4e87a

Browse files
Fix Windows compatibility of some tests
1 parent d2ef2b0 commit 9b4e87a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

tests/link/c/test_cmodule.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_cache_versioning():
128128
z = my_add(x)
129129
z_v = my_add_ver(x)
130130

131-
with tempfile.TemporaryDirectory() as dir_name:
131+
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as dir_name:
132132
cache = ModuleCache(dir_name)
133133

134134
lnk = CLinker().accept(FunctionGraph(outputs=[z]))

tests/link/c/test_op.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2+
import string
23
import subprocess
34
import sys
4-
import tempfile
55
from pathlib import Path
66

77
import numpy as np
@@ -37,7 +37,7 @@ class QuadraticCOpFunc(ExternalCOp):
3737
3838
def __init__(self, a, b, c):
3939
super().__init__(
40-
"{test_dir}/c_code/test_quadratic_function.c", "APPLY_SPECIFIC(compute_quadratic)"
40+
"{str(test_dir).replace("\\", "/")}/c_code/test_quadratic_function.c", "APPLY_SPECIFIC(compute_quadratic)"
4141
)
4242
self.a = a
4343
self.b = b
@@ -215,19 +215,22 @@ def get_hash(modname, seed=None):
215215
def test_ExternalCOp_c_code_cache_version():
216216
"""Make sure the C cache versions produced by `ExternalCOp` don't depend on `hash` seeding."""
217217

218-
with tempfile.NamedTemporaryFile(dir=".", suffix=".py") as tmp:
219-
tmp.write(externalcop_test_code.encode())
220-
tmp.seek(0)
218+
tmp = Path() / ("".join(np.random.choice(list(string.ascii_letters), 8)) + ".py")
219+
tmp.write_bytes(externalcop_test_code.encode())
220+
221+
try:
221222
modname = tmp.name
222223
out_1, err1, returncode1 = get_hash(modname, seed=428)
223224
out_2, err2, returncode2 = get_hash(modname, seed=3849)
224225
assert returncode1 == 0
225226
assert returncode2 == 0
226227
assert err1 == err2
227228

228-
hash_1, msg, _ = out_1.decode().split("\n")
229+
hash_1, msg, _ = out_1.decode().split(os.linesep)
229230
assert msg == "__success__"
230-
hash_2, msg, _ = out_2.decode().split("\n")
231+
hash_2, msg, _ = out_2.decode().split(os.linesep)
231232
assert msg == "__success__"
232233

233234
assert hash_1 == hash_2
235+
finally:
236+
tmp.unlink()

0 commit comments

Comments
 (0)