Skip to content

Commit 7e2dcbb

Browse files
committed
Fixed bug with --no-headers --tsv, closes #295
1 parent 61b60f5 commit 7e2dcbb

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

sqlite_utils/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def insert_upsert_implementation(
720720
):
721721
db = sqlite_utils.Database(path)
722722
_load_extensions(db, load_extension)
723-
if delimiter or quotechar or sniff or no_headers:
723+
if (delimiter or quotechar or sniff or no_headers) and not tsv:
724724
csv = True
725725
if (nl + csv + tsv) >= 2:
726726
raise click.ClickException("Use just one of --nl, --csv or --tsv")

tests/test_cli.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,25 +2205,27 @@ def test_long_csv_column_value(tmpdir):
22052205

22062206

22072207
@pytest.mark.parametrize(
2208-
"args",
2208+
"args,tsv",
22092209
(
2210-
["--csv", "--no-headers"],
2211-
["--no-headers"],
2210+
(["--csv", "--no-headers"], False),
2211+
(["--no-headers"], False),
2212+
(["--tsv", "--no-headers"], True),
22122213
),
22132214
)
2214-
def test_csv_import_no_headers(tmpdir, args):
2215+
def test_import_no_headers(tmpdir, args, tsv):
22152216
db_path = str(tmpdir / "test.db")
22162217
csv_path = str(tmpdir / "test.csv")
22172218
csv_file = open(csv_path, "w")
2218-
csv_file.write("Cleo,Dog,5\n")
2219-
csv_file.write("Tracy,Spider,7\n")
2219+
sep = "\t" if tsv else ","
2220+
csv_file.write("Cleo{sep}Dog{sep}5\n".format(sep=sep))
2221+
csv_file.write("Tracy{sep}Spider{sep}7\n".format(sep=sep))
22202222
csv_file.close()
22212223
result = CliRunner().invoke(
22222224
cli.cli,
22232225
["insert", db_path, "creatures", csv_path] + args,
22242226
catch_exceptions=False,
22252227
)
2226-
assert result.exit_code == 0
2228+
assert result.exit_code == 0, result.output
22272229
db = Database(db_path)
22282230
schema = db["creatures"].schema
22292231
assert schema == (

0 commit comments

Comments
 (0)