|
| 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 | + |
1 | 26 | import numpy as np |
2 | 27 | import mkl_random |
3 | 28 | import pytest |
@@ -94,6 +119,20 @@ def test_patched_names(): |
94 | 119 | finally: |
95 | 120 | mkl_random.restore() |
96 | 121 |
|
| 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 |
97 | 136 |
|
98 | 137 | def test_patch_redundant_patching(): |
99 | 138 | orig_normal = np.random.normal |
|
0 commit comments