fix: validate CSV export cursors before writing

This commit is contained in:
Rami Abdelrazzaq 2026-09-13 13:15:08 -05:00
commit 6f064ce6ee
2 changed files with 10 additions and 13 deletions

View file

@ -40,10 +40,12 @@ def test_rows_to_csv_file_tsv():
db.close()
def test_rows_to_csv_file_requires_result_columns_for_header():
@pytest.mark.parametrize("header", (True, False))
def test_rows_to_csv_file_requires_result_columns(header):
db = sqlite3.connect(":memory:")
cursor = db.execute("create table creatures (id integer)")
output = io.StringIO(newline="")
with pytest.raises(ValueError, match="Cursor does not have result columns"):
rows_to_csv_file(cursor, output)
rows_to_csv_file(cursor, output, header=header)
assert output.getvalue() == ""
db.close()