2424# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
2626import numpy as np
27- import mkl_random
2827import pytest
2928
29+ import mkl_random
30+
31+
3032def test_is_patched ():
31- """
32- Test that is_patched() returns correct status.
33- """
33+ """Test that is_patched() returns correct status."""
3434 assert not mkl_random .is_patched ()
3535 mkl_random .monkey_patch (np )
3636 assert mkl_random .is_patched ()
3737 mkl_random .restore ()
3838 assert not mkl_random .is_patched ()
3939
40+
4041def test_monkey_patch_and_restore ():
41- """
42- Test that monkey_patch replaces and restore brings back original functions.
43- """
42+ """Test monkey_patch replacement and restore of original functions."""
4443 # Store original functions
4544 orig_normal = np .random .normal
4645 orig_randint = np .random .randint
@@ -55,8 +54,8 @@ def test_monkey_patch_and_restore():
5554 assert np .random .RandomState is not orig_RandomState
5655
5756 # Check that they are from mkl_random
58- assert np .random .normal is mkl_random .mklrand . normal
59- assert np .random .RandomState is mkl_random .mklrand . RandomState
57+ assert np .random .normal is mkl_random .normal
58+ assert np .random .RandomState is mkl_random .RandomState
6059
6160 finally :
6261 mkl_random .restore ()
@@ -67,10 +66,9 @@ def test_monkey_patch_and_restore():
6766 assert np .random .randint is orig_randint
6867 assert np .random .RandomState is orig_RandomState
6968
69+
7070def test_context_manager ():
71- """
72- Test that the context manager patches and automatically restores.
73- """
71+ """Test context manager patching and automatic restoration."""
7472 orig_uniform = np .random .uniform
7573 assert not mkl_random .is_patched ()
7674
@@ -84,10 +82,9 @@ def test_context_manager():
8482 assert not mkl_random .is_patched ()
8583 assert np .random .uniform is orig_uniform
8684
85+
8786def test_patched_functions_callable ():
88- """
89- Smoke test to ensure some patched functions can be called without error.
90- """
87+ """Smoke test that patched functions are callable without errors."""
9188 mkl_random .monkey_patch (np )
9289 try :
9390 # These calls should now be routed to mkl_random's implementations
@@ -105,10 +102,9 @@ def test_patched_functions_callable():
105102 finally :
106103 mkl_random .restore ()
107104
105+
108106def test_patched_names ():
109- """
110- Test that patched_names() returns a list of patched symbols.
111- """
107+ """Test that patched_names() returns patched symbol names."""
112108 try :
113109 mkl_random .monkey_patch (np )
114110 names = mkl_random .patched_names ()
@@ -119,21 +115,20 @@ def test_patched_names():
119115 finally :
120116 mkl_random .restore ()
121117
118+
122119def test_monkey_patch_strict_raises_attribute_error ():
123- """
124- Test that strict mode raises AttributeError when patching non-existent names.
125- """
120+ """Test strict mode raises AttributeError for missing patch names."""
126121 # Attempt to patch a clearly non-existent symbol in strict mode.
127122 with pytest .raises (AttributeError ):
128123 mkl_random .monkey_patch (np , strict = True , names = ["nonexistent_symbol" ])
129124
125+
130126def test_use_in_numpy_is_alias_for_monkey_patch ():
131- """
132- Test that use_in_numpy is a backward-compatible alias for monkey_patch.
133- """
127+ """Test use_in_numpy remains a backward-compatible alias."""
134128 assert hasattr (mkl_random , "use_in_numpy" )
135129 assert mkl_random .use_in_numpy is mkl_random .monkey_patch
136130
131+
137132def test_patch_redundant_patching ():
138133 orig_normal = np .random .normal
139134 assert not mkl_random .is_patched ()
@@ -142,11 +137,11 @@ def test_patch_redundant_patching():
142137 mkl_random .monkey_patch (np )
143138
144139 assert mkl_random .is_patched ()
145- assert np .random .normal is mkl_random .mklrand . normal
140+ assert np .random .normal is mkl_random .normal
146141
147142 mkl_random .restore ()
148143 assert mkl_random .is_patched ()
149- assert np .random .normal is mkl_random .mklrand . normal
144+ assert np .random .normal is mkl_random .normal
150145
151146 mkl_random .restore ()
152147 assert not mkl_random .is_patched ()
0 commit comments