File: test_sniff.py

package info (click to toggle)
sqlite-utils 4.0~a0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,320 kB
  • sloc: python: 14,310; makefile: 33; ansic: 26; javascript: 21; sh: 5
file content (25 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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"},
    ]