-
-
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.
Patch the actual numpy import, not just the module
- Loading branch information
1 parent
bea4487
commit ced0caa
Showing
2 changed files
with
60 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
|
||
|
||
orig_import = __import__ | ||
|
||
|
||
def no_numpy_import(*args, **kwargs): | ||
print(args[0]) | ||
if args and args[0].startswith("numpy"): | ||
raise ImportError | ||
elif "name" in kwargs and kwargs["name"].startswith("numpy"): | ||
raise ImportError | ||
else: | ||
return orig_import(*args, **kwargs) | ||
|
||
|
||
with patch("builtins.__import__", no_numpy_import): | ||
from uncertainties import ( | ||
correlated_values, | ||
correlated_values_norm, | ||
correlation_matrix, | ||
ufloat, | ||
) | ||
|
||
|
||
def test_no_numpy(): | ||
nom_values = [1, 2, 3] | ||
std_devs = [0.1, 0.2, 0.3] | ||
cov = [ | ||
[1, 0, 0], | ||
[0, 1, 0], | ||
[0, 0, 1], | ||
] | ||
|
||
with pytest.raises( | ||
NotImplementedError, | ||
match="not able to import numpy", | ||
): | ||
_ = correlated_values(nom_values, cov) | ||
|
||
with pytest.raises( | ||
NotImplementedError, | ||
match="not able to import numpy", | ||
): | ||
_ = correlated_values_norm( | ||
list(zip(nom_values, std_devs)), | ||
cov, | ||
) | ||
|
||
x = ufloat(1, 0.1) | ||
y = ufloat(2, 0.2) | ||
z = ufloat(3, 0.3) | ||
|
||
with pytest.raises( | ||
NotImplementedError, | ||
match="not able to import numpy", | ||
): | ||
_ = correlation_matrix([x, y, z]) |
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