--stop-after option, closes #561

This commit is contained in:
Simon Willison 2023-06-27 11:50:04 -07:00
commit 8c739558f7
4 changed files with 43 additions and 0 deletions

View file

@ -229,6 +229,31 @@ def test_insert_csv_tsv(content, options, db_path, tmpdir):
assert [{"foo": "1", "bar": "2", "baz": "cat,dog"}] == list(db["data"].rows)
@pytest.mark.parametrize(
"input,args",
(
(
json.dumps(
[{"name": "One"}, {"name": "Two"}, {"name": "Three"}, {"name": "Four"}]
),
[],
),
("name\nOne\nTwo\nThree\nFour\n", ["--csv"]),
),
)
def test_insert_stop_after(tmpdir, input, args):
db_path = str(tmpdir / "data.db")
result = CliRunner().invoke(
cli.cli,
["insert", db_path, "rows", "-", "--stop-after", "2"] + args,
input=input,
)
assert 0 == result.exit_code
assert [{"name": "One"}, {"name": "Two"}] == list(
Database(db_path).query("select * from rows")
)
@pytest.mark.parametrize(
"options",
(