Skip to content

Commit 1f403ad

Browse files
committed
fix: bot review
1 parent c56e34b commit 1f403ad

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

mkl_random/src/_patch.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class mkl_random(ContextDecorator):
256256
--------
257257
>>> import numpy as np
258258
>>> import mkl_random
259-
>>> with mkl_random.mkl_random():
259+
>>> with mkl_random.mkl_random(np):
260260
... x = np.random.normal(size=10)
261261
"""
262262
def __init__(self, numpy_module=None, names=None, strict=False):

mkl_random/tests/test_patch.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
# Copyright (c) 2017, Intel Corporation
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright notice,
7+
# this list of conditions and the following disclaimer.
8+
# * Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# * Neither the name of Intel Corporation nor the names of its contributors
12+
# may be used to endorse or promote products derived from this software
13+
# without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
19+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
126
import numpy as np
227
import mkl_random
328
import pytest
@@ -94,6 +119,20 @@ def test_patched_names():
94119
finally:
95120
mkl_random.restore()
96121

122+
def test_monkey_patch_strict_raises_attribute_error():
123+
"""
124+
Test that strict mode raises AttributeError when patching non-existent names.
125+
"""
126+
# Attempt to patch a clearly non-existent symbol in strict mode.
127+
with pytest.raises(AttributeError):
128+
mkl_random.monkey_patch(np, strict=True, names=["nonexistent_symbol"])
129+
130+
def 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+
"""
134+
assert hasattr(mkl_random, "use_in_numpy")
135+
assert mkl_random.use_in_numpy is mkl_random.monkey_patch
97136

98137
def test_patch_redundant_patching():
99138
orig_normal = np.random.normal

0 commit comments

Comments
 (0)