Skip to content

Commit fd9b988

Browse files
committed
Stub in failing test on icdiff
1 parent d317a20 commit fd9b988

File tree

3 files changed

+66
-13
lines changed

3 files changed

+66
-13
lines changed

tests/fakes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ def __init__(self, *args, **kwargs):
66
def __add__(self, other):
77
return self
88

9+
def __eq__(self, other):
10+
return self
11+
12+
def __iter__(self):
13+
yield False
14+
915
def __lt__(self, other):
1016
raise ValueError(
1117
'Fake for: The truth value of any array with more than one element is ambiguous.'

tests/test_fake_numpy_array.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33
from fakes import FakeNumpyArray
44

55

6-
def test():
6+
@pytest.fixture
7+
def fake():
8+
return FakeNumpyArray([1, 2, 3])
9+
10+
11+
# --- INTEGRATED ---
12+
13+
14+
def test_in_test(fake):
15+
"""
16+
FakeNumpyArray can be used to equate to False in a test assertion, this
17+
means this fake can be used to trigger pytest to try to generate a diff
18+
(gets us into this plugin's code).
719
"""
8-
FakeNumpyArray can be used to trigger a ValueError
20+
result = all(fake == 2)
21+
22+
assert result is False
23+
24+
25+
def test_in_icdiff(fake):
26+
"""
27+
A FakeNumpyArray instance will trigger a ValueError when pytest-icdiff
28+
checks it before diffing.
929
"""
1030
left = FakeNumpyArray([1, 2, 3])
1131
right = 1
@@ -14,39 +34,45 @@ def test():
1434
abs(left + right) < 19999
1535

1636

17-
def test_init():
37+
# --- PARTS ---
38+
39+
40+
def test_init(fake):
1841
"""
1942
FakeNumpyArray can init with a list.
2043
"""
21-
result = FakeNumpyArray([1, 2, 3])
44+
result = fake
2245

2346
assert isinstance(result, FakeNumpyArray)
2447

2548

26-
def test_add():
49+
def test_eq(fake):
2750
"""
28-
FakeNumpyArray returns instance of itself when `+ 1` is applied to it.
51+
FakeNumpyArray returns instance of itself when `==` is applied to it.
2952
"""
30-
fake = FakeNumpyArray()
53+
result = fake == 1
54+
55+
assert isinstance(result, FakeNumpyArray)
56+
3157

58+
def test_add(fake):
59+
"""
60+
FakeNumpyArray returns instance of itself when `+ 1` is applied to it.
61+
"""
3262
result = fake + 1
3363

3464
assert isinstance(result, FakeNumpyArray)
3565

3666

37-
def test_abs():
38-
fake = FakeNumpyArray()
39-
67+
def test_abs(fake):
4068
result = abs(fake)
4169

4270
assert isinstance(result, FakeNumpyArray)
4371

4472

45-
def test_bool():
73+
def test_bool(fake):
4674
"""
4775
Attempting to use a FakeNumpyArray in a boolean expression raises.
4876
"""
49-
fake = FakeNumpyArray()
50-
5177
with pytest.raises(ValueError):
5278
fake < 19999

tests/test_pytest_icdiff.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,24 @@ def test_one():
289289
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
290290
assert len(output.splitlines()) < 50
291291
assert "---" in output # context split marker
292+
293+
294+
def test_np_arrays_can_use_equals(testdir) -> None:
295+
"""
296+
NP iterables will fall back to pytest default output
297+
"""
298+
testdir.copy_example('tests/fakes.py')
299+
testdir.makepyfile("""
300+
from fakes import FakeNumpyArray
301+
302+
def test():
303+
result = FakeNumpyArray([1, 2, 3])
304+
305+
assert all(result == 2)
306+
""")
307+
308+
result = testdir.runpytest()
309+
310+
output = result.stdout.str()
311+
assert 'ValueError' not in output
312+
assert 'AssertionError' in output

0 commit comments

Comments
 (0)