3232def test_is_patched ():
3333 """Test that is_patched() returns correct status."""
3434 assert not mkl_random .is_patched ()
35- mkl_random .monkey_patch (np )
35+ mkl_random .patch_numpy_random (np )
3636 assert mkl_random .is_patched ()
37- mkl_random .restore ()
37+ mkl_random .restore_numpy_random ()
3838 assert not mkl_random .is_patched ()
3939
4040
41- def test_monkey_patch_and_restore ():
42- """Test monkey_patch replacement and restore of original functions."""
41+ def test_patch_and_restore ():
42+ """Test patch replacement and restore of original functions."""
4343 # Store original functions
4444 orig_normal = np .random .normal
4545 orig_randint = np .random .randint
4646 orig_RandomState = np .random .RandomState
4747
4848 try :
49- mkl_random .monkey_patch (np )
49+ mkl_random .patch_numpy_random (np )
5050
5151 # Check that functions are now different objects
5252 assert np .random .normal is not orig_normal
@@ -58,7 +58,7 @@ def test_monkey_patch_and_restore():
5858 assert np .random .RandomState is mkl_random .RandomState
5959
6060 finally :
61- mkl_random .restore ()
61+ mkl_random .restore_numpy_random ()
6262
6363 # Check that original functions are restored
6464 assert mkl_random .is_patched () is False
@@ -85,7 +85,7 @@ def test_context_manager():
8585
8686def test_patched_functions_callable ():
8787 """Smoke test that patched functions are callable without errors."""
88- mkl_random .monkey_patch (np )
88+ mkl_random .patch_numpy_random (np )
8989 try :
9090 # These calls should now be routed to mkl_random's implementations
9191 x = np .random .standard_normal (size = 100 )
@@ -100,53 +100,51 @@ def test_patched_functions_callable():
100100 assert z .shape == (10 ,)
101101
102102 finally :
103- mkl_random .restore ()
103+ mkl_random .restore_numpy_random ()
104104
105105
106106def test_patched_names ():
107107 """Test that patched_names() returns patched symbol names."""
108108 try :
109- mkl_random .monkey_patch (np )
109+ mkl_random .patch_numpy_random (np )
110110 names = mkl_random .patched_names ()
111111 assert isinstance (names , list )
112112 assert len (names ) > 0
113113 assert "normal" in names
114114 assert "RandomState" in names
115115 finally :
116- mkl_random .restore ()
116+ mkl_random .restore_numpy_random ()
117117
118118
119- def test_monkey_patch_strict_raises_attribute_error ():
119+ def test_patch_strict_raises_attribute_error ():
120120 """Test strict mode raises AttributeError for missing patch names."""
121121 # Attempt to patch a clearly non-existent symbol in strict mode.
122122 with pytest .raises (AttributeError ):
123- mkl_random .monkey_patch (np , strict = True , names = ["nonexistent_symbol" ])
124-
125-
126- def test_use_in_numpy_is_alias_for_monkey_patch ():
127- """Test use_in_numpy remains a backward-compatible alias."""
128- assert hasattr (mkl_random , "use_in_numpy" )
129- assert mkl_random .use_in_numpy is mkl_random .monkey_patch
123+ mkl_random .patch_numpy_random (
124+ np ,
125+ strict = True ,
126+ names = ["nonexistent_symbol" ],
127+ )
130128
131129
132130def test_patch_redundant_patching ():
133131 orig_normal = np .random .normal
134132 assert not mkl_random .is_patched ()
135133
136134 try :
137- mkl_random .monkey_patch (np )
138- mkl_random .monkey_patch (np )
135+ mkl_random .patch_numpy_random (np )
136+ mkl_random .patch_numpy_random (np )
139137 assert mkl_random .is_patched ()
140138 assert np .random .normal is mkl_random .mklrand .normal
141- mkl_random .restore ()
139+ mkl_random .restore_numpy_random ()
142140 assert mkl_random .is_patched ()
143141 assert np .random .normal is mkl_random .mklrand .normal
144- mkl_random .restore ()
142+ mkl_random .restore_numpy_random ()
145143 assert not mkl_random .is_patched ()
146144 assert np .random .normal is orig_normal
147145 finally :
148146 while mkl_random .is_patched ():
149- mkl_random .restore ()
147+ mkl_random .restore_numpy_random ()
150148
151149
152150def test_patch_reentrant ():
0 commit comments