14
14
15
15
16
16
@pytest .mark .parametrize ("data" , [(0 , 0 , 0 , 0 ), (1 , 3 , 4 , 5 , 6 ), (2 , 4 )])
17
- def test_product (data : tuple [int , ...]):
17
+ def test_product (data : tuple [int , ...]) -> None :
18
18
assert product (data ) == np .prod (data )
19
19
20
20
21
21
# todo: test
22
- def test_concurrent_map (): ...
22
+ def test_concurrent_map () -> None : ...
23
23
24
24
25
25
# todo: test
26
- def test_to_thread (): ...
26
+ def test_to_thread () -> None : ...
27
27
28
28
29
29
# todo: test
30
- def test_enum_names (): ...
30
+ def test_enum_names () -> None : ...
31
31
32
32
33
33
# todo: test
34
- def test_parse_enum (): ...
34
+ def test_parse_enum () -> None : ...
35
35
36
36
37
37
@pytest .mark .parametrize ("data" , [("foo" , "bar" ), (10 , 11 )])
38
- def test_parse_name_invalid (data : tuple [Any , Any ]):
38
+ def test_parse_name_invalid (data : tuple [Any , Any ]) -> None :
39
39
observed , expected = data
40
40
if isinstance (observed , str ):
41
41
with pytest .raises (ValueError , match = f"Expected '{ expected } '. Got { observed } instead." ):
@@ -48,47 +48,71 @@ def test_parse_name_invalid(data: tuple[Any, Any]):
48
48
49
49
50
50
@pytest .mark .parametrize ("data" , [("foo" , "foo" ), ("10" , "10" )])
51
- def test_parse_name_valid (data : tuple [Any , Any ]):
51
+ def test_parse_name_valid (data : tuple [Any , Any ]) -> None :
52
52
observed , expected = data
53
53
assert parse_name (observed , expected ) == observed
54
54
55
55
56
56
@pytest .mark .parametrize ("data" , [0 , 1 , "hello" , "f" ])
57
- def test_parse_indexing_order_invalid (data ) :
57
+ def test_parse_indexing_order_invalid (data : Any ) -> None :
58
58
with pytest .raises (ValueError , match = "Expected one of" ):
59
59
parse_indexing_order (data )
60
60
61
61
62
62
@pytest .mark .parametrize ("data" , ["C" , "F" ])
63
- def parse_indexing_order_valid (data : Literal ["C" , "F" ]):
63
+ def parse_indexing_order_valid (data : Literal ["C" , "F" ]) -> None :
64
64
assert parse_indexing_order (data ) == data
65
65
66
66
67
- @pytest .mark .parametrize ("data" , [("0" , 1 , 2 , 3 ), {"0" : "0" }, []])
68
- def test_parse_shapelike_invalid (data : Any ):
69
- if isinstance (data , Iterable ):
70
- if len (data ) == 0 :
71
- with pytest .raises (ValueError , match = "Expected at least one element." ):
72
- parse_shapelike (data )
73
- else :
74
- with pytest .raises (TypeError , match = "Expected an iterable of integers" ):
75
- parse_shapelike (data )
76
- else :
77
- with pytest .raises (TypeError , match = "Expected an iterable." ):
78
- parse_shapelike (data )
67
+ @pytest .mark .parametrize ("data" , [lambda v : v , slice (None )])
68
+ def test_parse_shapelike_invalid_single_type (data : Any ) -> None :
69
+ """
70
+ Test that we get the expected error message when passing in a value that is not an integer
71
+ or an iterable of integers.
72
+ """
73
+ with pytest .raises (TypeError , match = "Expected an integer or an iterable of integers." ):
74
+ parse_shapelike (data )
75
+
76
+
77
+ def test_parse_shapelike_invalid_single_value () -> None :
78
+ """
79
+ Test that we get the expected error message when passing in a negative integer.
80
+ """
81
+ with pytest .raises (ValueError , match = "Expected a non-negative integer." ):
82
+ parse_shapelike (- 1 )
83
+
84
+
85
+ @pytest .mark .parametrize ("data" , ["shape" , ("0" , 1 , 2 , 3 ), {"0" : "0" }, ((1 , 2 ), (2 , 2 )), (4.0 , 2 )])
86
+ def test_parse_shapelike_invalid_iterable_types (data : Any ) -> None :
87
+ """
88
+ Test that we get the expected error message when passing in an iterable containing
89
+ non-integer elements
90
+ """
91
+ with pytest .raises (TypeError , match = "Expected an iterable of integers" ):
92
+ parse_shapelike (data )
93
+
94
+
95
+ @pytest .mark .parametrize ("data" , [(1 , 2 , 3 , - 1 ), (- 10 ,)])
96
+ def test_parse_shapelike_invalid_iterable_values (data : Any ) -> None :
97
+ """
98
+ Test that we get the expected error message when passing in an iterable containing negative
99
+ integers
100
+ """
101
+ with pytest .raises (ValueError , match = "Expected all values to be non-negative." ):
102
+ parse_shapelike (data )
79
103
80
104
81
- @pytest .mark .parametrize ("data" , [range (10 ), [0 , 1 , 2 , 3 ], (3 , 4 , 5 )])
82
- def test_parse_shapelike_valid (data : Iterable [Any ]) :
105
+ @pytest .mark .parametrize ("data" , [range (10 ), [0 , 1 , 2 , 3 ], (3 , 4 , 5 ), () ])
106
+ def test_parse_shapelike_valid (data : Iterable [int ]) -> None :
83
107
assert parse_shapelike (data ) == tuple (data )
84
108
85
109
86
110
# todo: more dtypes
87
111
@pytest .mark .parametrize ("data" , [("uint8" , np .uint8 ), ("float64" , np .float64 )])
88
- def parse_dtype (data : tuple [str , np .dtype ]):
112
+ def parse_dtype (data : tuple [str , np .dtype ]) -> None :
89
113
unparsed , parsed = data
90
114
assert parse_dtype (unparsed ) == parsed
91
115
92
116
93
117
# todo: figure out what it means to test this
94
- def test_parse_fill_value (): ...
118
+ def test_parse_fill_value () -> None : ...
0 commit comments