mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-29 05:14:28 +02:00
Split test to filter out pytest.PytestUnraisableExceptionWarning
This commit is contained in:
parent
96f3500b40
commit
41fb5225bc
1 changed files with 24 additions and 13 deletions
|
|
@ -62,26 +62,37 @@ def test_dayfirst_yearfirst(fresh_db, recipe, kwargs, expected):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
|
||||||
@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime"))
|
@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime"))
|
||||||
@pytest.mark.parametrize("errors", (None, recipes.SET_NULL, recipes.IGNORE))
|
def test_dateparse_errors_raises(fresh_db, fn):
|
||||||
def test_dateparse_errors(fresh_db, fn, errors):
|
"""Test that invalid dates raise errors when errors=None"""
|
||||||
fresh_db["example"].insert_all(
|
fresh_db["example"].insert_all(
|
||||||
[
|
[
|
||||||
{"id": 1, "dt": "invalid"},
|
{"id": 1, "dt": "invalid"},
|
||||||
],
|
],
|
||||||
pk="id",
|
pk="id",
|
||||||
)
|
)
|
||||||
if errors is None:
|
# Exception in SQLite callback surfaces as OperationalError
|
||||||
# Should raise an error
|
with pytest.raises(sqlite3.OperationalError):
|
||||||
with pytest.raises(sqlite3.OperationalError):
|
fresh_db["example"].convert("dt", lambda value: getattr(recipes, fn)(value))
|
||||||
fresh_db["example"].convert("dt", lambda value: getattr(recipes, fn)(value))
|
|
||||||
else:
|
|
||||||
fresh_db["example"].convert(
|
@pytest.mark.parametrize("fn", ("parsedate", "parsedatetime"))
|
||||||
"dt", lambda value: getattr(recipes, fn)(value, errors=errors)
|
@pytest.mark.parametrize("errors", (recipes.SET_NULL, recipes.IGNORE))
|
||||||
)
|
def test_dateparse_errors_handled(fresh_db, fn, errors):
|
||||||
rows = list(fresh_db["example"].rows)
|
"""Test error handling modes for invalid dates"""
|
||||||
expected = [{"id": 1, "dt": None if errors is recipes.SET_NULL else "invalid"}]
|
fresh_db["example"].insert_all(
|
||||||
assert rows == expected
|
[
|
||||||
|
{"id": 1, "dt": "invalid"},
|
||||||
|
],
|
||||||
|
pk="id",
|
||||||
|
)
|
||||||
|
fresh_db["example"].convert(
|
||||||
|
"dt", lambda value: getattr(recipes, fn)(value, errors=errors)
|
||||||
|
)
|
||||||
|
rows = list(fresh_db["example"].rows)
|
||||||
|
expected = [{"id": 1, "dt": None if errors is recipes.SET_NULL else "invalid"}]
|
||||||
|
assert rows == expected
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("delimiter", [None, ";", "-"])
|
@pytest.mark.parametrize("delimiter", [None, ";", "-"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue