@@ -233,27 +233,27 @@ def test_compat(self, dtype):
233
233
def test_construction_from_string (self , dtype ):
234
234
result = DatetimeTZDtype .construct_from_string ("datetime64[ns, US/Eastern]" )
235
235
assert is_dtype_equal (dtype , result )
236
- msg = "Cannot construct a 'DatetimeTZDtype' from 'foo'"
237
- with pytest .raises (TypeError , match = msg ):
238
- DatetimeTZDtype .construct_from_string ("foo" )
239
-
240
- def test_construct_from_string_raises (self ):
241
- with pytest .raises (TypeError , match = "notatz" ):
242
- DatetimeTZDtype .construct_from_string ("datetime64[ns, notatz]" )
243
-
244
- msg = "'construct_from_string' expects a string, got <class 'list'>"
245
- with pytest .raises (TypeError , match = re .escape (msg )):
246
- # list instead of string
247
- DatetimeTZDtype .construct_from_string (["datetime64[ns, notatz]" ])
248
236
249
- msg = "^Cannot construct a 'DatetimeTZDtype'"
250
- with pytest .raises (TypeError , match = msg ):
237
+ @pytest .mark .parametrize (
238
+ "string" ,
239
+ [
240
+ "foo" ,
241
+ "datetime64[ns, notatz]" ,
251
242
# non-nano unit
252
- DatetimeTZDtype .construct_from_string ("datetime64[ps, UTC]" )
243
+ "datetime64[ps, UTC]" ,
244
+ # dateutil str that returns None from gettz
245
+ "datetime64[ns, dateutil/invalid]" ,
246
+ ],
247
+ )
248
+ def test_construct_from_string_invalid_raises (self , string ):
249
+ msg = f"Cannot construct a 'DatetimeTZDtype' from '{ string } '"
250
+ with pytest .raises (TypeError , match = re .escape (msg )):
251
+ DatetimeTZDtype .construct_from_string (string )
253
252
253
+ def test_construct_from_string_wrong_type_raises (self ):
254
+ msg = "'construct_from_string' expects a string, got <class 'list'>"
254
255
with pytest .raises (TypeError , match = msg ):
255
- # dateutil str that returns None from gettz
256
- DatetimeTZDtype .construct_from_string ("datetime64[ns, dateutil/invalid]" )
256
+ DatetimeTZDtype .construct_from_string (["datetime64[ns, notatz]" ])
257
257
258
258
def test_is_dtype (self , dtype ):
259
259
assert not DatetimeTZDtype .is_dtype (None )
0 commit comments