mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-23 18:34:13 +02:00
Handle empty input in rows_from_file
This commit is contained in:
parent
43d5d3331f
commit
b143fc4913
2 changed files with 9 additions and 0 deletions
|
|
@ -368,6 +368,8 @@ def rows_from_file(
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"rows_from_file() requires a file-like object that supports peek(), such as io.BytesIO"
|
"rows_from_file() requires a file-like object that supports peek(), such as io.BytesIO"
|
||||||
)
|
)
|
||||||
|
if not first_bytes:
|
||||||
|
return (), Format.CSV
|
||||||
if first_bytes.startswith((b"[", b"{")):
|
if first_bytes.startswith((b"[", b"{")):
|
||||||
# TODO: Detect newline-JSON
|
# TODO: Detect newline-JSON
|
||||||
return rows_from_file(buffered, format=Format.JSON)
|
return rows_from_file(buffered, format=Format.JSON)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,13 @@ def test_rows_from_file_detect_format(input, expected_format):
|
||||||
assert rows_list == [{"id": "1", "name": "Cleo"}]
|
assert rows_list == [{"id": "1", "name": "Cleo"}]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("input", (b"", b" \n\t"))
|
||||||
|
def test_rows_from_file_empty_input(input):
|
||||||
|
rows, format = rows_from_file(BytesIO(input))
|
||||||
|
assert format == Format.CSV
|
||||||
|
assert list(rows) == []
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"ignore_extras,extras_key,expected",
|
"ignore_extras,extras_key,expected",
|
||||||
(
|
(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue