mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-17 14:54:10 +02:00
sqlite-utils insert --sniff option, closes #230
This commit is contained in:
parent
1e9eb875a6
commit
99ff0a288c
7 changed files with 74 additions and 9 deletions
5
tests/sniff/example1.csv
Normal file
5
tests/sniff/example1.csv
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
id,species,name,age
|
||||
1,dog,Cleo,5
|
||||
2,dog,Pancakes,4
|
||||
3,cat,Mozie,8
|
||||
4,spider,"Daisy, the tarantula",6
|
||||
|
5
tests/sniff/example2.csv
Normal file
5
tests/sniff/example2.csv
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
id;species;name;age
|
||||
1;dog;Cleo;5
|
||||
2;dog;Pancakes;4
|
||||
3;cat;Mozie;8
|
||||
4;spider;"Daisy, the tarantula";6
|
||||
|
5
tests/sniff/example3.csv
Normal file
5
tests/sniff/example3.csv
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
id,species,name,age
|
||||
1,dog,Cleo,5
|
||||
2,dog,Pancakes,4
|
||||
3,cat,Mozie,8
|
||||
4,spider,'Daisy, the tarantula',6
|
||||
|
5
tests/sniff/example4.csv
Normal file
5
tests/sniff/example4.csv
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
id species name age
|
||||
1 dog Cleo 5
|
||||
2 dog Pancakes 4
|
||||
3 cat Mozie 8
|
||||
4 spider 'Daisy, the tarantula' 6
|
||||
|
25
tests/test_sniff.py
Normal file
25
tests/test_sniff.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from sqlite_utils import cli, Database
|
||||
from click.testing import CliRunner
|
||||
import pathlib
|
||||
import pytest
|
||||
|
||||
sniff_dir = pathlib.Path(__file__).parent / "sniff"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("filepath", sniff_dir.glob("example*"))
|
||||
def test_sniff(tmpdir, filepath):
|
||||
db_path = str(tmpdir / "test.db")
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli.cli,
|
||||
["insert", db_path, "creatures", str(filepath), "--sniff"],
|
||||
catch_exceptions=False,
|
||||
)
|
||||
assert result.exit_code == 0, result.stdout
|
||||
db = Database(db_path)
|
||||
assert list(db["creatures"].rows) == [
|
||||
{"id": "1", "species": "dog", "name": "Cleo", "age": "5"},
|
||||
{"id": "2", "species": "dog", "name": "Pancakes", "age": "4"},
|
||||
{"id": "3", "species": "cat", "name": "Mozie", "age": "8"},
|
||||
{"id": "4", "species": "spider", "name": "Daisy, the tarantula", "age": "6"},
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue