44
55import numpy as np
66from numpy .testing import assert_array_equal
7- from nose . tools import assert_raises , eq_ as eq
7+ import pytest
88
99
10- from zarr .indexing import (normalize_integer_selection , replace_ellipsis , oindex , oindex_set )
10+ from zarr .indexing import (normalize_integer_selection , replace_ellipsis , oindex ,
11+ oindex_set )
1112import zarr
1213
1314
1415def test_normalize_integer_selection ():
1516
16- eq ( 1 , normalize_integer_selection (1 , 100 ) )
17- eq ( 99 , normalize_integer_selection (- 1 , 100 ) )
18- with assert_raises (IndexError ):
17+ assert 1 == normalize_integer_selection (1 , 100 )
18+ assert 99 == normalize_integer_selection (- 1 , 100 )
19+ with pytest . raises (IndexError ):
1920 normalize_integer_selection (100 , 100 )
20- with assert_raises (IndexError ):
21+ with pytest . raises (IndexError ):
2122 normalize_integer_selection (1000 , 100 )
22- with assert_raises (IndexError ):
23+ with pytest . raises (IndexError ):
2324 normalize_integer_selection (- 1000 , 100 )
2425
2526
2627def test_replace_ellipsis ():
2728
2829 # 1D, single item
29- eq (( 0 ,), replace_ellipsis (0 , (100 ,) ))
30+ assert ( 0 ,) == replace_ellipsis (0 , (100 ,))
3031
3132 # 1D
32- eq (( slice (None ),), replace_ellipsis (Ellipsis , (100 ,) ))
33- eq (( slice (None ),), replace_ellipsis (slice (None ), (100 ,) ))
34- eq (( slice (None , 100 ),), replace_ellipsis (slice (None , 100 ), (100 ,) ))
35- eq (( slice (0 , None ),), replace_ellipsis (slice (0 , None ), (100 ,) ))
36- eq (( slice (None ),), replace_ellipsis ((slice (None ), Ellipsis ), (100 ,) ))
37- eq (( slice (None ),), replace_ellipsis ((Ellipsis , slice (None )), (100 ,) ))
33+ assert ( slice (None ),) == replace_ellipsis (Ellipsis , (100 ,))
34+ assert ( slice (None ),) == replace_ellipsis (slice (None ), (100 ,))
35+ assert ( slice (None , 100 ),) == replace_ellipsis (slice (None , 100 ), (100 ,))
36+ assert ( slice (0 , None ),) == replace_ellipsis (slice (0 , None ), (100 ,))
37+ assert ( slice (None ),) == replace_ellipsis ((slice (None ), Ellipsis ), (100 ,))
38+ assert ( slice (None ),) == replace_ellipsis ((Ellipsis , slice (None )), (100 ,))
3839
3940 # 2D, single item
40- eq (( 0 , 0 ), replace_ellipsis ((0 , 0 ), (100 , 100 ) ))
41- eq (( - 1 , 1 ), replace_ellipsis ((- 1 , 1 ), (100 , 100 ) ))
41+ assert ( 0 , 0 ) == replace_ellipsis ((0 , 0 ), (100 , 100 ))
42+ assert ( - 1 , 1 ) == replace_ellipsis ((- 1 , 1 ), (100 , 100 ))
4243
4344 # 2D, single col/row
44- eq (( 0 , slice (None )), replace_ellipsis ((0 , slice (None )), (100 , 100 ) ))
45- eq (( 0 , slice (None )), replace_ellipsis ((0 ,), (100 , 100 ) ))
46- eq (( slice (None ), 0 ), replace_ellipsis ((slice (None ), 0 ), (100 , 100 ) ))
45+ assert ( 0 , slice (None )) == replace_ellipsis ((0 , slice (None )), (100 , 100 ))
46+ assert ( 0 , slice (None )) == replace_ellipsis ((0 ,), (100 , 100 ))
47+ assert ( slice (None ), 0 ) == replace_ellipsis ((slice (None ), 0 ), (100 , 100 ))
4748
4849 # 2D slice
49- eq ((slice (None ), slice (None )),
50- replace_ellipsis (Ellipsis , (100 , 100 )))
51- eq ((slice (None ), slice (None )),
52- replace_ellipsis (slice (None ), (100 , 100 )))
53- eq ((slice (None ), slice (None )),
54- replace_ellipsis ((slice (None ), slice (None )), (100 , 100 )))
55- eq ((slice (None ), slice (None )),
56- replace_ellipsis ((Ellipsis , slice (None )), (100 , 100 )))
57- eq ((slice (None ), slice (None )),
58- replace_ellipsis ((slice (None ), Ellipsis ), (100 , 100 )))
59- eq ((slice (None ), slice (None )),
60- replace_ellipsis ((slice (None ), Ellipsis , slice (None )), (100 , 100 )))
61- eq ((slice (None ), slice (None )),
62- replace_ellipsis ((Ellipsis , slice (None ), slice (None )), (100 , 100 )))
63- eq ((slice (None ), slice (None )),
64- replace_ellipsis ((slice (None ), slice (None ), Ellipsis ), (100 , 100 )))
50+ assert ((slice (None ), slice (None )) ==
51+ replace_ellipsis (Ellipsis , (100 , 100 )))
52+ assert ((slice (None ), slice (None )) ==
53+ replace_ellipsis (slice (None ), (100 , 100 )))
54+ assert ((slice (None ), slice (None )) ==
55+ replace_ellipsis ((slice (None ), slice (None )), (100 , 100 )))
56+ assert ((slice (None ), slice (None )) ==
57+ replace_ellipsis ((Ellipsis , slice (None )), (100 , 100 )))
58+ assert ((slice (None ), slice (None )) ==
59+ replace_ellipsis ((slice (None ), Ellipsis ), (100 , 100 )))
60+ assert ((slice (None ), slice (None )) ==
61+ replace_ellipsis ((slice (None ), Ellipsis , slice (None )), (100 , 100 )))
62+ assert ((slice (None ), slice (None )) ==
63+ replace_ellipsis ((Ellipsis , slice (None ), slice (None )), (100 , 100 )))
64+ assert ((slice (None ), slice (None )) ==
65+ replace_ellipsis ((slice (None ), slice (None ), Ellipsis ), (100 , 100 )))
6566
6667
6768def test_get_basic_selection_0d ():
@@ -73,8 +74,8 @@ def test_get_basic_selection_0d():
7374
7475 assert_array_equal (a , z .get_basic_selection (Ellipsis ))
7576 assert_array_equal (a , z [...])
76- eq ( 42 , z .get_basic_selection (() ))
77- eq ( 42 , z [()])
77+ assert 42 == z .get_basic_selection (())
78+ assert 42 == z [()]
7879
7980 # test out param
8081 b = np .zeros_like (a )
@@ -88,12 +89,12 @@ def test_get_basic_selection_0d():
8889 z [()] = value
8990 assert_array_equal (a , z .get_basic_selection (Ellipsis ))
9091 assert_array_equal (a , z [...])
91- eq ( a [()], z .get_basic_selection (() ))
92- eq ( a [()], z [()])
93- eq ( b'aaa' , z .get_basic_selection ((), fields = 'foo' ) )
94- eq ( b'aaa' , z ['foo' ])
95- eq ( a [['foo' , 'bar' ]], z .get_basic_selection ((), fields = ['foo' , 'bar' ]) )
96- eq ( a [['foo' , 'bar' ]], z ['foo' , 'bar' ])
92+ assert a [()] == z .get_basic_selection (())
93+ assert a [()] == z [()]
94+ assert b'aaa' == z .get_basic_selection ((), fields = 'foo' )
95+ assert b'aaa' == z ['foo' ]
96+ assert a [['foo' , 'bar' ]] == z .get_basic_selection ((), fields = ['foo' , 'bar' ])
97+ assert a [['foo' , 'bar' ]] == z ['foo' , 'bar' ]
9798 # test out param
9899 b = np .zeros_like (a )
99100 z .get_basic_selection (Ellipsis , out = b )
@@ -201,9 +202,9 @@ def test_get_basic_selection_1d():
201202 [0 , 1 ], # fancy indexing
202203 ]
203204 for selection in bad_selections :
204- with assert_raises (IndexError ):
205+ with pytest . raises (IndexError ):
205206 z .get_basic_selection (selection )
206- with assert_raises (IndexError ):
207+ with pytest . raises (IndexError ):
207208 z [selection ]
208209
209210
@@ -277,9 +278,9 @@ def test_get_basic_selection_2d():
277278 (slice (None ), [0 , 1 ]),
278279 ]
279280 for selection in bad_selections :
280- with assert_raises (IndexError ):
281+ with pytest . raises (IndexError ):
281282 z .get_basic_selection (selection )
282- with assert_raises (IndexError ):
283+ with pytest . raises (IndexError ):
283284 z [selection ]
284285
285286
@@ -316,17 +317,17 @@ def test_set_basic_selection_0d():
316317 assert_array_equal (a , z )
317318 # with fields
318319 z .set_basic_selection (Ellipsis , v ['foo' ], fields = 'foo' )
319- eq ( v ['foo' ], z ['foo' ])
320- eq ( a ['bar' ], z ['bar' ])
321- eq ( a ['baz' ], z ['baz' ])
320+ assert v ['foo' ] == z ['foo' ]
321+ assert a ['bar' ] == z ['bar' ]
322+ assert a ['baz' ] == z ['baz' ]
322323 z ['bar' ] = v ['bar' ]
323- eq ( v ['foo' ], z ['foo' ])
324- eq ( v ['bar' ], z ['bar' ])
325- eq ( a ['baz' ], z ['baz' ])
324+ assert v ['foo' ] == z ['foo' ]
325+ assert v ['bar' ] == z ['bar' ]
326+ assert a ['baz' ] == z ['baz' ]
326327 # multiple field assignment not supported
327- with assert_raises (IndexError ):
328+ with pytest . raises (IndexError ):
328329 z .set_basic_selection (Ellipsis , v [['foo' , 'bar' ]], fields = ['foo' , 'bar' ])
329- with assert_raises (IndexError ):
330+ with pytest . raises (IndexError ):
330331 z [..., 'foo' , 'bar' ] = v [['foo' , 'bar' ]]
331332
332333
@@ -353,11 +354,11 @@ def test_get_orthogonal_selection_1d_bool():
353354 _test_get_orthogonal_selection (a , z , ix )
354355
355356 # test errors
356- with assert_raises (IndexError ):
357+ with pytest . raises (IndexError ):
357358 z .oindex [np .zeros (50 , dtype = bool )] # too short
358- with assert_raises (IndexError ):
359+ with pytest . raises (IndexError ):
359360 z .oindex [np .zeros (2000 , dtype = bool )] # too long
360- with assert_raises (IndexError ):
361+ with pytest . raises (IndexError ):
361362 z .oindex [[[True , False ], [False , True ]]] # too many dimensions
362363
363364
@@ -398,9 +399,9 @@ def test_get_orthogonal_selection_1d_int():
398399 [[2 , 4 ], [6 , 8 ]], # too many dimensions
399400 ]
400401 for selection in bad_selections :
401- with assert_raises (IndexError ):
402+ with pytest . raises (IndexError ):
402403 z .get_orthogonal_selection (selection )
403- with assert_raises (IndexError ):
404+ with pytest . raises (IndexError ):
404405 z .oindex [selection ]
405406
406407
@@ -461,9 +462,9 @@ def test_get_orthogonal_selection_2d():
461462 _test_get_orthogonal_selection (a , z , selection )
462463
463464 for selection in basic_selections_2d_bad :
464- with assert_raises (IndexError ):
465+ with pytest . raises (IndexError ):
465466 z .get_orthogonal_selection (selection )
466- with assert_raises (IndexError ):
467+ with pytest . raises (IndexError ):
467468 z .oindex [selection ]
468469
469470
@@ -766,9 +767,9 @@ def test_get_coordinate_selection_1d():
766767 [- (a .shape [0 ] + 1 )], # out of bounds
767768 ]
768769 for selection in bad_selections :
769- with assert_raises (IndexError ):
770+ with pytest . raises (IndexError ):
770771 z .get_coordinate_selection (selection )
771- with assert_raises (IndexError ):
772+ with pytest . raises (IndexError ):
772773 z .vindex [selection ]
773774
774775
@@ -816,16 +817,16 @@ def test_get_coordinate_selection_2d():
816817 [1 , 0 , 0 ]])
817818 _test_get_coordinate_selection (a , z , (ix0 , ix1 ))
818819
819- with assert_raises (IndexError ):
820+ with pytest . raises (IndexError ):
820821 selection = slice (5 , 15 ), [1 , 2 , 3 ]
821822 z .get_coordinate_selection (selection )
822- with assert_raises (IndexError ):
823+ with pytest . raises (IndexError ):
823824 selection = [1 , 2 , 3 ], slice (5 , 15 )
824825 z .get_coordinate_selection (selection )
825- with assert_raises (IndexError ):
826+ with pytest . raises (IndexError ):
826827 selection = Ellipsis , [1 , 2 , 3 ]
827828 z .get_coordinate_selection (selection )
828- with assert_raises (IndexError ):
829+ with pytest . raises (IndexError ):
829830 selection = Ellipsis
830831 z .get_coordinate_selection (selection )
831832
@@ -864,9 +865,9 @@ def test_set_coordinate_selection_1d():
864865 _test_set_coordinate_selection (v , a , z , ix )
865866
866867 for selection in coordinate_selections_1d_bad :
867- with assert_raises (IndexError ):
868+ with pytest . raises (IndexError ):
868869 z .set_coordinate_selection (selection , 42 )
869- with assert_raises (IndexError ):
870+ with pytest . raises (IndexError ):
870871 z .vindex [selection ] = 42
871872
872873
@@ -948,9 +949,9 @@ def test_get_mask_selection_1d():
948949 [[True , False ], [False , True ]], # too many dimensions
949950 ]
950951 for selection in bad_selections :
951- with assert_raises (IndexError ):
952+ with pytest . raises (IndexError ):
952953 z .get_mask_selection (selection )
953- with assert_raises (IndexError ):
954+ with pytest . raises (IndexError ):
954955 z .vindex [selection ]
955956
956957
@@ -969,11 +970,11 @@ def test_get_mask_selection_2d():
969970 _test_get_mask_selection (a , z , ix )
970971
971972 # test errors
972- with assert_raises (IndexError ):
973+ with pytest . raises (IndexError ):
973974 z .vindex [np .zeros ((1000 , 5 ), dtype = bool )] # too short
974- with assert_raises (IndexError ):
975+ with pytest . raises (IndexError ):
975976 z .vindex [np .zeros ((2000 , 10 ), dtype = bool )] # too long
976- with assert_raises (IndexError ):
977+ with pytest . raises (IndexError ):
977978 z .vindex [[True , False ]] # wrong no. dimensions
978979
979980
@@ -1002,9 +1003,9 @@ def test_set_mask_selection_1d():
10021003 _test_set_mask_selection (v , a , z , ix )
10031004
10041005 for selection in mask_selections_1d_bad :
1005- with assert_raises (IndexError ):
1006+ with pytest . raises (IndexError ):
10061007 z .set_mask_selection (selection , 42 )
1007- with assert_raises (IndexError ):
1008+ with pytest . raises (IndexError ):
10081009 z .vindex [selection ] = 42
10091010
10101011
@@ -1039,7 +1040,7 @@ def test_get_selection_out():
10391040 z .get_basic_selection (selection , out = out )
10401041 assert_array_equal (expect , out [:])
10411042
1042- with assert_raises (TypeError ):
1043+ with pytest . raises (TypeError ):
10431044 z .get_basic_selection (Ellipsis , out = [])
10441045
10451046 # orthogonal selections
@@ -1200,9 +1201,9 @@ def test_get_selections_with_fields():
12001201 assert_array_equal (expect , actual )
12011202
12021203 # missing/bad fields
1203- with assert_raises (IndexError ):
1204+ with pytest . raises (IndexError ):
12041205 z .get_basic_selection (Ellipsis , fields = ['notafield' ])
1205- with assert_raises (IndexError ):
1206+ with pytest . raises (IndexError ):
12061207 z .get_basic_selection (Ellipsis , fields = slice (None ))
12071208
12081209
@@ -1229,22 +1230,23 @@ def test_set_selections_with_fields():
12291230
12301231 for fields in fields_fixture :
12311232
1232- # currently multi-field assignment is not supported in numpy, so we won't support it either
1233+ # currently multi-field assignment is not supported in numpy, so we won't support
1234+ # it either
12331235 if isinstance (fields , list ) and len (fields ) > 1 :
1234- with assert_raises (IndexError ):
1236+ with pytest . raises (IndexError ):
12351237 z .set_basic_selection (Ellipsis , v , fields = fields )
1236- with assert_raises (IndexError ):
1238+ with pytest . raises (IndexError ):
12371239 z .set_orthogonal_selection ([0 , 2 ], v , fields = fields )
1238- with assert_raises (IndexError ):
1240+ with pytest . raises (IndexError ):
12391241 z .set_coordinate_selection ([0 , 2 ], v , fields = fields )
1240- with assert_raises (IndexError ):
1242+ with pytest . raises (IndexError ):
12411243 z .set_mask_selection ([True , False , True ], v , fields = fields )
12421244
12431245 else :
12441246
12451247 if isinstance (fields , list ) and len (fields ) == 1 :
1246- # work around numpy does not support multi-field assignment even if there is only
1247- # one field
1248+ # work around numpy does not support multi-field assignment even if there
1249+ # is only one field
12481250 key = fields [0 ]
12491251 elif isinstance (fields , list ) and len (fields ) == 0 :
12501252 # work around numpy ambiguity about what is a field selection
0 commit comments