-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* py: fix bug in cufinufft library fallback * py: add tests for fallback library loading * py: skip fallback tests in CI These tests checks that the fallback mechanism is working properly. In other words, if there is no bundled library, it should look in the system path (e.g. `LD_LIBRARY_PATH` on Unix systems) and try to load it from there. For some reason, these tests work locally, but in CI, the library is imported as usual, even with the patched function. Perhaps this has something to do with the fact that the module is already loaded, so `import finufft` is a no-op (this is evidenced by the fact that any `print` statement in `finufft._finufft` is not detected in the output).
- Loading branch information
Showing
5 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
|
||
import numpy as np | ||
from ctypes.util import find_library | ||
|
||
|
||
# Check to make sure the fallback mechanism works if there is no bundled | ||
# dynamic library. | ||
@pytest.mark.skip(reason="Patching seems to fail in CI") | ||
def test_fallback(mocker): | ||
def fake_load_library(lib_name, path): | ||
if lib_name in ["libcufinufft", "cufinufft"]: | ||
raise OSError() | ||
else: | ||
return np.ctypeslib.load_library(lib_name, path) | ||
|
||
# Block out the bundled library. | ||
mocker.patch("numpy.ctypeslib.load_library", fake_load_library) | ||
|
||
# Make sure an error is raised if no system library is found. | ||
if find_library("cufinufft") is None: | ||
with pytest.raises(ImportError, match="suitable cufinufft"): | ||
import cufinufft | ||
else: | ||
import cufinufft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
import numpy as np | ||
from ctypes.util import find_library | ||
|
||
@pytest.mark.skip(reason="Patching seems to fail in CI") | ||
def test_fallback(mocker): | ||
def fake_load_library(lib_name, path): | ||
if lib_name in ["libfinufft", "finufft"]: | ||
raise OSError() | ||
else: | ||
return np.ctypeslib.load_library(lib_name, path) | ||
|
||
mocker.patch("numpy.ctypeslib.load_library", fake_load_library) | ||
|
||
if find_library("finufft") is None: | ||
with pytest.raises(ImportError, match="suitable finufft"): | ||
import finufft | ||
else: | ||
import finufft |