mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-29 14:37:44 +01:00
Merge 9e64607012 into 9c66bafa52
This commit is contained in:
commit
f6cc2d0e77
2 changed files with 26 additions and 2 deletions
|
|
@ -31,7 +31,7 @@ def parsedate(
|
||||||
.date()
|
.date()
|
||||||
.isoformat()
|
.isoformat()
|
||||||
)
|
)
|
||||||
except parser.ParserError:
|
except (parser.ParserError, OverflowError):
|
||||||
if errors is IGNORE:
|
if errors is IGNORE:
|
||||||
return value
|
return value
|
||||||
elif errors is SET_NULL:
|
elif errors is SET_NULL:
|
||||||
|
|
@ -58,7 +58,7 @@ def parsedatetime(
|
||||||
return value
|
return value
|
||||||
try:
|
try:
|
||||||
return parser.parse(value, dayfirst=dayfirst, yearfirst=yearfirst).isoformat()
|
return parser.parse(value, dayfirst=dayfirst, yearfirst=yearfirst).isoformat()
|
||||||
except parser.ParserError:
|
except (parser.ParserError, OverflowError):
|
||||||
if errors is IGNORE:
|
if errors is IGNORE:
|
||||||
return value
|
return value
|
||||||
elif errors is SET_NULL:
|
elif errors is SET_NULL:
|
||||||
|
|
|
||||||
24
tests/test_recipe_overflow.py
Normal file
24
tests/test_recipe_overflow.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from sqlite_utils import recipes
|
||||||
|
|
||||||
|
|
||||||
|
OVERFLOWING_DATE = "999999999999999999999999999999-01-01"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime"))
|
||||||
|
def test_dateparse_overflow_raises_by_default(fn):
|
||||||
|
with pytest.raises(OverflowError):
|
||||||
|
getattr(recipes, fn)(OVERFLOWING_DATE)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime"))
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"errors,expected",
|
||||||
|
(
|
||||||
|
(recipes.IGNORE, OVERFLOWING_DATE),
|
||||||
|
(recipes.SET_NULL, None),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_dateparse_overflow_respects_errors(fn, errors, expected):
|
||||||
|
assert getattr(recipes, fn)(OVERFLOWING_DATE, errors=errors) == expected
|
||||||
Loading…
Add table
Add a link
Reference in a new issue