@@ -33,31 +33,40 @@ def test_init(self, data):
3333 assert_array_equal (g .delta , data ['delta' ])
3434
3535 def test_init_wrong_origin (self , data ):
36- with pytest .raises (TypeError ):
36+ with pytest .raises (TypeError ,
37+ match = (r"Dimension of origin is not the same as "
38+ r"grid dimension\." )):
3739 Grid (data ['griddata' ], origin = np .ones (4 ), delta = data ['delta' ])
3840
3941 def test_init_wrong_delta (self , data ):
40- with pytest .raises (TypeError ):
42+ with pytest .raises (TypeError ,
43+ match = (r"delta should be scalar or array-like of "
44+ r"len\(grid\.ndim\)" )):
4145 Grid (data ['griddata' ], origin = data ['origin' ], delta = np .ones (4 ))
4246
4347 def test_empty_Grid (self ):
4448 g = Grid ()
4549 assert isinstance (g , Grid )
4650
4751 def test_init_missing_delta_ValueError (self , data ):
48- with pytest .raises (ValueError ):
52+ with pytest .raises (ValueError ,
53+ match = "Wrong/missing data to set up Grid" ):
4954 Grid (data ['griddata' ], origin = data ['origin' ])
5055
5156 def test_init_missing_origin_ValueError (self , data ):
52- with pytest .raises (ValueError ):
57+ with pytest .raises (ValueError ,
58+ match = "Wrong/missing data to set up Grid" ):
5359 Grid (data ['griddata' ], delta = data ['delta' ])
5460
5561 def test_init_wrong_data_exception (self ):
56- with pytest .raises (IOError ):
57- Grid ("__does_not_exist__" )
58-
59- def test_load_wrong_fileformat_ValueError (self ):
60- with pytest .raises (ValueError ):
62+ fn = "__does_not_exist__"
63+ with pytest .raises (IOError ,
64+ match = r"\[Errno 2\] file not found:" + f" '{ fn } '" ):
65+ Grid (fn )
66+
67+ def test_load_unknown_fileformat_ValueError (self ):
68+ with pytest .raises (ValueError ,
69+ match = "Wrong/missing data to set up Grid" ):
6170 Grid (grid = True , file_format = "xxx" )
6271
6372 def test_equality (self , data ):
@@ -113,16 +122,19 @@ def test_compatibility_type(self, data):
113122
114123 def test_wrong_compatibile_type (self , data ):
115124 g = Grid (data ['griddata' ], origin = data ['origin' ] + 1 , delta = data ['delta' ])
116- with pytest .raises (TypeError ):
125+ with pytest .raises (TypeError ,
126+ match = "The argument cannot be arithmetically combined" ):
117127 data ['grid' ].check_compatible (g )
118128
119129 arr = np .zeros (data ['griddata' ].shape [- 1 ] + 1 ) # Not broadcastable
120- with pytest .raises (TypeError ):
130+ with pytest .raises (TypeError ,
131+ match = "The argument cannot be arithmetically combined" ):
121132 data ['grid' ].check_compatible (arr )
122133
123134 def test_non_orthonormal_boxes (self , data ):
124135 delta = np .eye (3 )
125- with pytest .raises (NotImplementedError ):
136+ with pytest .raises (NotImplementedError ,
137+ match = "Non-rectangular grids are not supported" ):
126138 Grid (data ['griddata' ], origin = data ['origin' ], delta = delta )
127139
128140 def test_centers (self , data ):
@@ -138,7 +150,7 @@ def test_centers(self, data):
138150 def test_resample_factor_failure (self , data ):
139151 pytest .importorskip ('scipy' )
140152
141- with pytest .raises (ValueError ):
153+ with pytest .raises (ValueError , match = "Factor must be positive" ):
142154 g = data ['grid' ].resample_factor (0 )
143155
144156 def test_resample_factor (self , data ):
@@ -176,32 +188,32 @@ def test_init_pickle_pathobjects(self, data, tmpdir):
176188
177189 @pytest .mark .parametrize ("fileformat" , ("pkl" , "PKL" , "pickle" , "python" ))
178190 def test_load_fileformat (self , data , pklfile , fileformat ):
179- h = Grid (pklfile , file_format = "pkl" )
191+ h = Grid (pklfile , file_format = fileformat )
180192 assert h == data ['grid' ]
181193
182- # At the moment, reading the file with the wrong parser does not give
183- # good error messages.
184- @pytest .mark .xfail
185- @pytest .mark .parametrize ("fileformat" , ("ccp4" , "plt" , "dx" ))
186- def test_load_wrong_fileformat (self , data , pklfile , fileformat ):
187- with pytest .raises ('ValueError' ):
194+ @pytest .mark .parametrize ("fileformat" , ("mrc" , "plt" , "dx" ))
195+ def test_load_wrong_fileformat_raises_ValueError (self , pklfile , fileformat ):
196+ # no error matching because ValueErrors can come from different
197+ # parts of the underlying file parser and have different messages
198+ with pytest .raises (ValueError ):
188199 Grid (pklfile , file_format = fileformat )
189200
190201 # just check that we can export without stupid failures; detailed
191202 # format checks in separate tests
192- @pytest .mark .parametrize ("fileformat" , ("dx" , "pkl" ))
203+ @pytest .mark .parametrize ("fileformat" , ("dx" , "mrc" , " pkl" ))
193204 def test_export (self , data , fileformat , tmpdir ):
194205 g = data ['grid' ]
195206 fn = tmpdir .mkdir ('grid_export' ).join ("grid.{}" .format (fileformat ))
196207 g .export (fn ) # check that path objects work
197208 h = Grid (fn ) # use format autodetection
198209 assert g == h
199210
200- @pytest .mark .parametrize ("fileformat" , ("ccp4" , " plt" ))
211+ @pytest .mark .parametrize ("fileformat" , ("plt" , ))
201212 def test_export_not_supported (self , data , fileformat , tmpdir ):
202213 g = data ['grid' ]
203- fn = tmpdir .mkdir ('grid_export' ).join ("grid.{}" .format (fileformat ))
204- with pytest .raises (ValueError ):
214+ fn = tmpdir .mkdir ('grid_export' ).join (f"grid.{ fileformat } " )
215+ with pytest .raises (ValueError ,
216+ match = f"File format { fileformat .upper ()} not available" ):
205217 g .export (fn )
206218
207219
0 commit comments