mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-01 15:04:11 +02:00
Implemented --tsv option, closes #41
This commit is contained in:
parent
ef112ffc94
commit
09316835e6
3 changed files with 69 additions and 9 deletions
|
|
@ -511,6 +511,38 @@ def test_insert_ignore(db_path, tmpdir):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"content,option",
|
||||
(("foo\tbar\tbaz\n1\t2\t3", "--tsv"), ("foo,bar,baz\n1,2,3", "--csv")),
|
||||
)
|
||||
def test_insert_csv_tsv(content, option, db_path, tmpdir):
|
||||
db = Database(db_path)
|
||||
file_path = str(tmpdir / "insert.csv-tsv")
|
||||
open(file_path, "w").write(content)
|
||||
result = CliRunner().invoke(cli.cli, ["insert", db_path, "data", file_path, option])
|
||||
assert 0 == result.exit_code
|
||||
assert [{"foo": "1", "bar": "2", "baz": "3"}] == list(db["data"].rows)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"options",
|
||||
(
|
||||
["--tsv", "--nl"],
|
||||
["--tsv", "--csv"],
|
||||
["--csv", "--nl"],
|
||||
["--csv", "--nl", "--tsv"],
|
||||
),
|
||||
)
|
||||
def test_only_allow_one_of_nl_tsv_csv(options, db_path, tmpdir):
|
||||
file_path = str(tmpdir / "insert.csv-tsv")
|
||||
open(file_path, "w").write("foo")
|
||||
result = CliRunner().invoke(
|
||||
cli.cli, ["insert", db_path, "data", file_path] + options
|
||||
)
|
||||
assert 0 != result.exit_code
|
||||
assert "Error: Use just one of --nl, --csv or --tsv" == result.output.strip()
|
||||
|
||||
|
||||
def test_upsert(db_path, tmpdir):
|
||||
test_insert_multiple_with_primary_key(db_path, tmpdir)
|
||||
json_path = str(tmpdir / "upsert.json")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue