Skip to content

Commit 4db7f41

Browse files
committed
TST: add test that monkeypatching can be circumvented
1 parent 1e9dfae commit 4db7f41

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

tests/test_testing.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Callable, Iterator
22
from types import ModuleType
3-
from typing import Any, cast
3+
from typing import Any, cast, final
44

55
import numpy as np
66
import pytest
@@ -362,6 +362,12 @@ def j(y: Array) -> "B":
362362
return B(y + 1.0)
363363

364364

365+
@final
366+
class eager:
367+
# this needs to be a staticmethod to appease the type checker
368+
non_materializable5 = staticmethod(non_materializable5)
369+
370+
365371
lazy_xp_function((B, "g"))
366372
lazy_xp_function((B, "w"))
367373
lazy_xp_function((B, "k"))
@@ -412,6 +418,11 @@ def test_static_methods_wrapped(self, xp: ModuleType, library: Backend):
412418
else:
413419
assert isinstance(foo.j(x), B)
414420

421+
def test_circumvention(self, xp: ModuleType):
422+
x = xp.asarray([1.0, 2.0])
423+
y = eager.non_materializable5(x)
424+
xp_assert_equal(y, x)
425+
415426

416427
def dask_raises(x: Array) -> Array:
417428
def _raises(x: Array) -> Array:

0 commit comments

Comments
 (0)