mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-15 13:04:10 +02:00
Fixed bug with --no-headers --tsv, closes #295
This commit is contained in:
parent
61b60f58ce
commit
7e2dcbbbea
2 changed files with 10 additions and 8 deletions
|
|
@ -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")
|
||||||
|
|
|
||||||
|
|
@ -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 == (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue