Fixed bug with --no-headers --tsv, closes #295

This commit is contained in:
Simon Willison 2021-08-18 13:18:54 -07:00
commit 7e2dcbbbea
2 changed files with 10 additions and 8 deletions

View file

@ -720,7 +720,7 @@ def insert_upsert_implementation(
): ):
db = sqlite_utils.Database(path) db = sqlite_utils.Database(path)
_load_extensions(db, load_extension) _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 csv = True
if (nl + csv + tsv) >= 2: if (nl + csv + tsv) >= 2:
raise click.ClickException("Use just one of --nl, --csv or --tsv") raise click.ClickException("Use just one of --nl, --csv or --tsv")

View file

@ -2205,25 +2205,27 @@ def test_long_csv_column_value(tmpdir):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"args", "args,tsv",
( (
["--csv", "--no-headers"], (["--csv", "--no-headers"], False),
["--no-headers"], (["--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") db_path = str(tmpdir / "test.db")
csv_path = str(tmpdir / "test.csv") csv_path = str(tmpdir / "test.csv")
csv_file = open(csv_path, "w") csv_file = open(csv_path, "w")
csv_file.write("Cleo,Dog,5\n") sep = "\t" if tsv else ","
csv_file.write("Tracy,Spider,7\n") 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() csv_file.close()
result = CliRunner().invoke( result = CliRunner().invoke(
cli.cli, cli.cli,
["insert", db_path, "creatures", csv_path] + args, ["insert", db_path, "creatures", csv_path] + args,
catch_exceptions=False, catch_exceptions=False,
) )
assert result.exit_code == 0 assert result.exit_code == 0, result.output
db = Database(db_path) db = Database(db_path)
schema = db["creatures"].schema schema = db["creatures"].schema
assert schema == ( assert schema == (