Skip to content

Commit

Permalink
Avoid Windows failures due to missing SYSTEMROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
moble authored Aug 20, 2024
1 parent 5c66571 commit e8263ec
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import subprocess
import platform
import os
import sys
import numpy as np
import quaternionic
Expand Down Expand Up @@ -123,13 +125,24 @@ def test_pyguvectorize():

@pytest.mark.skipif(sys.implementation.name.lower() == "pypy", reason="No numba on pypy")
def test_cache_disable(tmp_path):
# Stolen from https://github.com/pypa/setuptools/blob/477f713450ff57de126153f3034d032542916d03/setuptools/tests/test_distutils_adoption.py#L13-L22
def win_sr(env):
"""
On Windows, SYSTEMROOT must be present to avoid
> Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python
"""
if platform.system() == "Windows":
env["SYSTEMROOT"] = os.environ["SYSTEMROOT"]
return env

# First check caching works by default.
cache_dir = tmp_path / "enabled"
subprocess.run(
[sys.executable, "-c", "import quaternionic"],
env={
env=win_sr({
"NUMBA_CACHE_DIR": str(cache_dir),
},
}),
)

# Numba uses a subdirectory named `quaternionic_<hashstr>`, with the hashstr computed
Expand All @@ -147,9 +160,9 @@ def test_cache_disable(tmp_path):
cache_dir = tmp_path / "disabled"
subprocess.run(
[sys.executable, "-c", "import quaternionic"],
env={
env=win_sr({
"QUATERNIONIC_DISABLE_CACHE": "1",
"NUMBA_CACHE_DIR": str(cache_dir),
},
}),
)
assert (not cache_dir.exists()) or len(list(cache_dir.iterdir())) == 0

0 comments on commit e8263ec

Please sign in to comment.