File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ class FakeNumpyArray ():
2
+
3
+ def __init__ (self , * args , ** kwargs ):
4
+ pass
5
+
6
+ def __add__ (self , other ):
7
+ return self
8
+
9
+ def __lt__ (self , other ):
10
+ raise ValueError (
11
+ 'Fake for: The truth value of any array with more than one element is ambiguous.'
12
+ )
13
+
14
+ def __abs__ (self ):
15
+ return self
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from fakes import FakeNumpyArray
4
+
5
+
6
+ def test ():
7
+ """
8
+ FakeNumpyArray can be used to trigger a ValueError
9
+ """
10
+ left = FakeNumpyArray ([1 , 2 , 3 ])
11
+ right = 1
12
+
13
+ with pytest .raises (ValueError ):
14
+ abs (left + right ) < 19999
15
+
16
+
17
+ def test_init ():
18
+ """
19
+ FakeNumpyArray can init with a list.
20
+ """
21
+ result = FakeNumpyArray ([1 , 2 , 3 ])
22
+
23
+ assert isinstance (result , FakeNumpyArray )
24
+
25
+
26
+ def test_add ():
27
+ """
28
+ FakeNumpyArray returns instance of itself when `+ 1` is applied to it.
29
+ """
30
+ fake = FakeNumpyArray ()
31
+
32
+ result = fake + 1
33
+
34
+ assert isinstance (result , FakeNumpyArray )
35
+
36
+
37
+ def test_abs ():
38
+ fake = FakeNumpyArray ()
39
+
40
+ result = abs (fake )
41
+
42
+ assert isinstance (result , FakeNumpyArray )
43
+
44
+
45
+ def test_bool ():
46
+ """
47
+ Attempting to use a FakeNumpyArray in a boolean expression raises.
48
+ """
49
+ fake = FakeNumpyArray ()
50
+
51
+ with pytest .raises (ValueError ):
52
+ fake < 19999
You can’t perform that action at this time.
0 commit comments