mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-26 10:17:04 +01:00
Fix CSV dialect class type support
This commit is contained in:
parent
85fe3c3407
commit
fb53549500
2 changed files with 14 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import csv
|
import csv
|
||||||
from typing import Any, Sequence, TextIO, Union
|
from typing import Any, Sequence, TextIO, Type, Union
|
||||||
|
|
||||||
CsvDialect = Union[str, csv.Dialect]
|
CsvDialect = Union[str, csv.Dialect, Type[csv.Dialect]]
|
||||||
|
|
||||||
|
|
||||||
def rows_to_csv_file(
|
def rows_to_csv_file(
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import csv
|
||||||
import io
|
import io
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
@ -40,6 +41,17 @@ def test_rows_to_csv_file_tsv():
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
def test_rows_to_csv_file_accepts_dialect_class():
|
||||||
|
class PipeDialect(csv.excel):
|
||||||
|
delimiter = "|"
|
||||||
|
|
||||||
|
db, cursor = _cursor()
|
||||||
|
output = io.StringIO(newline="")
|
||||||
|
rows_to_csv_file(cursor, output, dialect=PipeDialect, lineterminator="\n")
|
||||||
|
assert output.getvalue() == "id|name\n1|Cleo\n2|Cardi, Jr.\n"
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("header", (True, False))
|
@pytest.mark.parametrize("header", (True, False))
|
||||||
def test_rows_to_csv_file_requires_result_columns(header):
|
def test_rows_to_csv_file_requires_result_columns(header):
|
||||||
db = sqlite3.connect(":memory:")
|
db = sqlite3.connect(":memory:")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue