@@ -4133,15 +4133,12 @@ def test_ip_types(self):
4133
4133
def test_mask_size (self ):
4134
4134
assert_raises (ValueError , np .putmask , np .array ([1 , 2 , 3 ]), [True ], 5 )
4135
4135
4136
- def tst_byteorder (self , dtype ):
4136
+ @pytest .mark .parametrize ('dtype' , ('>i4' , '<i4' ))
4137
+ def test_byteorder (self , dtype ):
4137
4138
x = np .array ([1 , 2 , 3 ], dtype )
4138
4139
np .putmask (x , [True , False , True ], - 1 )
4139
4140
assert_array_equal (x , [- 1 , 2 , - 1 ])
4140
4141
4141
- def test_ip_byteorder (self ):
4142
- for dtype in ('>i4' , '<i4' ):
4143
- self .tst_byteorder (dtype )
4144
-
4145
4142
def test_record_array (self ):
4146
4143
# Note mixed byteorder.
4147
4144
rec = np .array ([(- 5 , 2.0 , 3.0 ), (5.0 , 4.0 , 3.0 )],
@@ -4191,14 +4188,11 @@ def test_wrap(self):
4191
4188
assert_array_equal (x .take ([2 ], axis = 0 , mode = 'wrap' )[0 ], x [0 ])
4192
4189
assert_array_equal (x .take ([3 ], axis = 0 , mode = 'wrap' )[0 ], x [1 ])
4193
4190
4194
- def tst_byteorder (self , dtype ):
4191
+ @pytest .mark .parametrize ('dtype' , ('>i4' , '<i4' ))
4192
+ def test_byteorder (self , dtype ):
4195
4193
x = np .array ([1 , 2 , 3 ], dtype )
4196
4194
assert_array_equal (x .take ([0 , 2 , 1 ]), [1 , 3 , 2 ])
4197
4195
4198
- def test_ip_byteorder (self ):
4199
- for dtype in ('>i4' , '<i4' ):
4200
- self .tst_byteorder (dtype )
4201
-
4202
4196
def test_record_array (self ):
4203
4197
# Note mixed byteorder.
4204
4198
rec = np .array ([(- 5 , 2.0 , 3.0 ), (5.0 , 4.0 , 3.0 )],
@@ -4574,19 +4568,16 @@ def test_locale(self):
4574
4568
4575
4569
4576
4570
class TestFromBuffer (object ):
4577
- def tst_basic (self , buffer , expected , kwargs ):
4578
- assert_array_equal (np .frombuffer (buffer ,** kwargs ), expected )
4579
-
4580
- def test_ip_basic (self ):
4581
- for byteorder in ['<' , '>' ]:
4582
- for dtype in [float , int , complex ]:
4583
- dt = np .dtype (dtype ).newbyteorder (byteorder )
4584
- x = (np .random .random ((4 , 7 ))* 5 ).astype (dt )
4585
- buf = x .tobytes ()
4586
- self .tst_basic (buf , x .flat , {'dtype' :dt })
4571
+ @pytest .mark .parametrize ('byteorder' , ['<' , '>' ])
4572
+ @pytest .mark .parametrize ('dtype' , [float , int , complex ])
4573
+ def test_basic (self , byteorder , dtype ):
4574
+ dt = np .dtype (dtype ).newbyteorder (byteorder )
4575
+ x = (np .random .random ((4 , 7 )) * 5 ).astype (dt )
4576
+ buf = x .tobytes ()
4577
+ assert_array_equal (np .frombuffer (buf , dtype = dt ), x .flat )
4587
4578
4588
4579
def test_empty (self ):
4589
- self . tst_basic (b'' , np .array ([]), {} )
4580
+ assert_array_equal ( np . frombuffer (b'' ) , np .array ([]))
4590
4581
4591
4582
4592
4583
class TestFlat (object ):
@@ -5940,9 +5931,10 @@ def test_broadcast2(self):
5940
5931
NEIGH_MODE = {'zero' : 0 , 'one' : 1 , 'constant' : 2 , 'circular' : 3 , 'mirror' : 4 }
5941
5932
5942
5933
5934
+ @pytest .mark .parametrize ('dt' , [float , Decimal ], ids = ['float' , 'object' ])
5943
5935
class TestNeighborhoodIter (object ):
5944
5936
# Simple, 2d tests
5945
- def _test_simple2d (self , dt ):
5937
+ def test_simple2d (self , dt ):
5946
5938
# Test zero and one padding for simple data type
5947
5939
x = np .array ([[0 , 1 ], [2 , 3 ]], dtype = dt )
5948
5940
r = [np .array ([[0 , 0 , 0 ], [0 , 0 , 1 ]], dtype = dt ),
@@ -5969,13 +5961,7 @@ def _test_simple2d(self, dt):
5969
5961
x , [- 1 , 0 , - 1 , 1 ], 4 , NEIGH_MODE ['constant' ])
5970
5962
assert_array_equal (l , r )
5971
5963
5972
- def test_simple2d (self ):
5973
- self ._test_simple2d (float )
5974
-
5975
- def test_simple2d_object (self ):
5976
- self ._test_simple2d (Decimal )
5977
-
5978
- def _test_mirror2d (self , dt ):
5964
+ def test_mirror2d (self , dt ):
5979
5965
x = np .array ([[0 , 1 ], [2 , 3 ]], dtype = dt )
5980
5966
r = [np .array ([[0 , 0 , 1 ], [0 , 0 , 1 ]], dtype = dt ),
5981
5967
np .array ([[0 , 1 , 1 ], [0 , 1 , 1 ]], dtype = dt ),
@@ -5985,14 +5971,8 @@ def _test_mirror2d(self, dt):
5985
5971
x , [- 1 , 0 , - 1 , 1 ], x [0 ], NEIGH_MODE ['mirror' ])
5986
5972
assert_array_equal (l , r )
5987
5973
5988
- def test_mirror2d (self ):
5989
- self ._test_mirror2d (float )
5990
-
5991
- def test_mirror2d_object (self ):
5992
- self ._test_mirror2d (Decimal )
5993
-
5994
5974
# Simple, 1d tests
5995
- def _test_simple (self , dt ):
5975
+ def test_simple (self , dt ):
5996
5976
# Test padding with constant values
5997
5977
x = np .linspace (1 , 5 , 5 ).astype (dt )
5998
5978
r = [[0 , 1 , 2 ], [1 , 2 , 3 ], [2 , 3 , 4 ], [3 , 4 , 5 ], [4 , 5 , 0 ]]
@@ -6010,14 +5990,8 @@ def _test_simple(self, dt):
6010
5990
x , [- 1 , 1 ], x [4 ], NEIGH_MODE ['constant' ])
6011
5991
assert_array_equal (l , r )
6012
5992
6013
- def test_simple_float (self ):
6014
- self ._test_simple (float )
6015
-
6016
- def test_simple_object (self ):
6017
- self ._test_simple (Decimal )
6018
-
6019
5993
# Test mirror modes
6020
- def _test_mirror (self , dt ):
5994
+ def test_mirror (self , dt ):
6021
5995
x = np .linspace (1 , 5 , 5 ).astype (dt )
6022
5996
r = np .array ([[2 , 1 , 1 , 2 , 3 ], [1 , 1 , 2 , 3 , 4 ], [1 , 2 , 3 , 4 , 5 ],
6023
5997
[2 , 3 , 4 , 5 , 5 ], [3 , 4 , 5 , 5 , 4 ]], dtype = dt )
@@ -6026,26 +6000,15 @@ def _test_mirror(self, dt):
6026
6000
assert_ ([i .dtype == dt for i in l ])
6027
6001
assert_array_equal (l , r )
6028
6002
6029
- def test_mirror (self ):
6030
- self ._test_mirror (float )
6031
-
6032
- def test_mirror_object (self ):
6033
- self ._test_mirror (Decimal )
6034
-
6035
6003
# Circular mode
6036
- def _test_circular (self , dt ):
6004
+ def test_circular (self , dt ):
6037
6005
x = np .linspace (1 , 5 , 5 ).astype (dt )
6038
6006
r = np .array ([[4 , 5 , 1 , 2 , 3 ], [5 , 1 , 2 , 3 , 4 ], [1 , 2 , 3 , 4 , 5 ],
6039
6007
[2 , 3 , 4 , 5 , 1 ], [3 , 4 , 5 , 1 , 2 ]], dtype = dt )
6040
6008
l = _multiarray_tests .test_neighborhood_iterator (
6041
6009
x , [- 2 , 2 ], x [0 ], NEIGH_MODE ['circular' ])
6042
6010
assert_array_equal (l , r )
6043
6011
6044
- def test_circular (self ):
6045
- self ._test_circular (float )
6046
-
6047
- def test_circular_object (self ):
6048
- self ._test_circular (Decimal )
6049
6012
6050
6013
# Test stacking neighborhood iterators
6051
6014
class TestStackedNeighborhoodIter (object ):
0 commit comments