Skip to content

Commit

Permalink
Fixed bug with --no-headers --tsv, closes #295
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Aug 18, 2021
1 parent 61b60f5 commit 7e2dcbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sqlite_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def insert_upsert_implementation(
):
db = sqlite_utils.Database(path)
_load_extensions(db, load_extension)
if delimiter or quotechar or sniff or no_headers:
if (delimiter or quotechar or sniff or no_headers) and not tsv:
csv = True
if (nl + csv + tsv) >= 2:
raise click.ClickException("Use just one of --nl, --csv or --tsv")
Expand Down
16 changes: 9 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,25 +2205,27 @@ def test_long_csv_column_value(tmpdir):


@pytest.mark.parametrize(
"args",
"args,tsv",
(
["--csv", "--no-headers"],
["--no-headers"],
(["--csv", "--no-headers"], False),
(["--no-headers"], False),
(["--tsv", "--no-headers"], True),
),
)
def test_csv_import_no_headers(tmpdir, args):
def test_import_no_headers(tmpdir, args, tsv):
db_path = str(tmpdir / "test.db")
csv_path = str(tmpdir / "test.csv")
csv_file = open(csv_path, "w")
csv_file.write("Cleo,Dog,5\n")
csv_file.write("Tracy,Spider,7\n")
sep = "\t" if tsv else ","
csv_file.write("Cleo{sep}Dog{sep}5\n".format(sep=sep))
csv_file.write("Tracy{sep}Spider{sep}7\n".format(sep=sep))
csv_file.close()
result = CliRunner().invoke(
cli.cli,
["insert", db_path, "creatures", csv_path] + args,
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output
db = Database(db_path)
schema = db["creatures"].schema
assert schema == (
Expand Down

0 comments on commit 7e2dcbb

Please sign in to comment.