mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 18:04:32 +02:00
parent
42ec59d8ee
commit
7684bbf097
3 changed files with 59 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from sqlite_utils import cli, Database
|
||||
from click.testing import CliRunner
|
||||
import pytest
|
||||
import json
|
||||
|
||||
|
||||
def test_memory_basic():
|
||||
|
|
@ -34,6 +35,47 @@ def test_memory_csv(tmpdir, sql_from, use_stdin):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_stdin", (True, False))
|
||||
def test_memory_csv_encoding(tmpdir, use_stdin):
|
||||
latin1_csv = (
|
||||
b"date,name,latitude,longitude\n" b"2020-03-04,S\xe3o Paulo,-23.561,-46.645\n"
|
||||
)
|
||||
input = None
|
||||
if use_stdin:
|
||||
input = latin1_csv
|
||||
csv_path = "-"
|
||||
sql_from = "stdin"
|
||||
else:
|
||||
csv_path = str(tmpdir / "test.csv")
|
||||
with open(csv_path, "wb") as fp:
|
||||
fp.write(latin1_csv)
|
||||
sql_from = "test"
|
||||
# Without --encoding should error:
|
||||
assert (
|
||||
CliRunner()
|
||||
.invoke(
|
||||
cli.cli,
|
||||
["memory", csv_path, "select * from {}".format(sql_from), "--nl"],
|
||||
input=input,
|
||||
)
|
||||
.exit_code
|
||||
== 1
|
||||
)
|
||||
# With --encoding should work:
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
["memory", "-", "select * from stdin", "--encoding", "latin-1", "--nl"],
|
||||
input=latin1_csv,
|
||||
)
|
||||
assert result.exit_code == 0, result.output
|
||||
assert json.loads(result.output.strip()) == {
|
||||
"date": "2020-03-04",
|
||||
"name": "S\u00e3o Paulo",
|
||||
"latitude": "-23.561",
|
||||
"longitude": "-46.645",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("extra_args", ([], ["select 1"]))
|
||||
def test_memory_dump(extra_args):
|
||||
result = CliRunner().invoke(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue