@@ -62,26 +62,37 @@ def test_dayfirst_yearfirst(fresh_db, recipe, kwargs, expected):
6262 ]
6363
6464
65+ @pytest .mark .filterwarnings ("ignore::pytest.PytestUnraisableExceptionWarning" )
6566@pytest .mark .parametrize ("fn" , ("parsedate" , "parsedatetime" ))
66- @ pytest . mark . parametrize ( "errors" , ( None , recipes . SET_NULL , recipes . IGNORE ))
67- def test_dateparse_errors ( fresh_db , fn , errors ):
67+ def test_dateparse_errors_raises ( fresh_db , fn ):
68+ """Test that invalid dates raise errors when errors=None"""
6869 fresh_db ["example" ].insert_all (
6970 [
7071 {"id" : 1 , "dt" : "invalid" },
7172 ],
7273 pk = "id" ,
7374 )
74- if errors is None :
75- # Should raise an error
76- with pytest .raises (sqlite3 .OperationalError ):
77- fresh_db ["example" ].convert ("dt" , lambda value : getattr (recipes , fn )(value ))
78- else :
79- fresh_db ["example" ].convert (
80- "dt" , lambda value : getattr (recipes , fn )(value , errors = errors )
81- )
82- rows = list (fresh_db ["example" ].rows )
83- expected = [{"id" : 1 , "dt" : None if errors is recipes .SET_NULL else "invalid" }]
84- assert rows == expected
75+ # Exception in SQLite callback surfaces as OperationalError
76+ with pytest .raises (sqlite3 .OperationalError ):
77+ fresh_db ["example" ].convert ("dt" , lambda value : getattr (recipes , fn )(value ))
78+
79+
80+ @pytest .mark .parametrize ("fn" , ("parsedate" , "parsedatetime" ))
81+ @pytest .mark .parametrize ("errors" , (recipes .SET_NULL , recipes .IGNORE ))
82+ def test_dateparse_errors_handled (fresh_db , fn , errors ):
83+ """Test error handling modes for invalid dates"""
84+ fresh_db ["example" ].insert_all (
85+ [
86+ {"id" : 1 , "dt" : "invalid" },
87+ ],
88+ pk = "id" ,
89+ )
90+ fresh_db ["example" ].convert (
91+ "dt" , lambda value : getattr (recipes , fn )(value , errors = errors )
92+ )
93+ rows = list (fresh_db ["example" ].rows )
94+ expected = [{"id" : 1 , "dt" : None if errors is recipes .SET_NULL else "invalid" }]
95+ assert rows == expected
8596
8697
8798@pytest .mark .parametrize ("delimiter" , [None , ";" , "-" ])
0 commit comments