Skip to content

Commit

Permalink
Fixed bug with sqlite-utils upsert --detect-types, closes #362
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 6, 2022
1 parent 413f8ed commit a7b29bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions sqlite_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ def upsert(
not_null=not_null,
default=default,
encoding=encoding,
detect_types=detect_types,
load_extension=load_extension,
silent=silent,
)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,24 @@ def _test():
_test()


@pytest.mark.parametrize("option", ("-d", "--detect-types"))
def test_upsert_detect_types(tmpdir, option):
db_path = str(tmpdir / "test.db")
data = "id,name,age,weight\n1,Cleo,6,45.5\n2,Dori,1,3.5"
result = CliRunner().invoke(
cli.cli,
["upsert", db_path, "creatures", "-", "--csv", "--pk", "id"] + [option],
catch_exceptions=False,
input=data,
)
assert result.exit_code == 0
db = Database(db_path)
assert list(db["creatures"].rows) == [
{"id": 1, "name": "Cleo", "age": 6, "weight": 45.5},
{"id": 2, "name": "Dori", "age": 1, "weight": 3.5},
]


@pytest.mark.parametrize(
"input,expected",
(
Expand Down

0 comments on commit a7b29bf

Please sign in to comment.