|
1 | 1 | import os |
| 2 | +import string |
2 | 3 | import subprocess |
3 | 4 | import sys |
4 | | -import tempfile |
5 | 5 | from pathlib import Path |
6 | 6 |
|
7 | 7 | import numpy as np |
@@ -37,7 +37,7 @@ class QuadraticCOpFunc(ExternalCOp): |
37 | 37 |
|
38 | 38 | def __init__(self, a, b, c): |
39 | 39 | super().__init__( |
40 | | - "{test_dir}/c_code/test_quadratic_function.c", "APPLY_SPECIFIC(compute_quadratic)" |
| 40 | + "{str(test_dir).replace(os.sep, "/")}/c_code/test_quadratic_function.c", "APPLY_SPECIFIC(compute_quadratic)" |
41 | 41 | ) |
42 | 42 | self.a = a |
43 | 43 | self.b = b |
@@ -215,19 +215,22 @@ def get_hash(modname, seed=None): |
215 | 215 | def test_ExternalCOp_c_code_cache_version(): |
216 | 216 | """Make sure the C cache versions produced by `ExternalCOp` don't depend on `hash` seeding.""" |
217 | 217 |
|
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: |
221 | 222 | modname = tmp.name |
222 | 223 | out_1, err1, returncode1 = get_hash(modname, seed=428) |
223 | 224 | out_2, err2, returncode2 = get_hash(modname, seed=3849) |
224 | 225 | assert returncode1 == 0 |
225 | 226 | assert returncode2 == 0 |
226 | 227 | assert err1 == err2 |
227 | 228 |
|
228 | | - hash_1, msg, _ = out_1.decode().split("\n") |
| 229 | + hash_1, msg, _ = out_1.decode().split(os.linesep) |
229 | 230 | assert msg == "__success__" |
230 | | - hash_2, msg, _ = out_2.decode().split("\n") |
| 231 | + hash_2, msg, _ = out_2.decode().split(os.linesep) |
231 | 232 | assert msg == "__success__" |
232 | 233 |
|
233 | 234 | assert hash_1 == hash_2 |
| 235 | + finally: |
| 236 | + tmp.unlink() |
0 commit comments