sqlite-utils/tests/test_introspect.py
Simon Willison 5deb65f062 Now you just 'from sqlite_utils import Database'
Plus fixed ad_id in the Russian ads example in the docs
2018-07-30 20:30:23 -07:00

28 lines
676 B
Python

from sqlite_utils import Database
import sqlite3
import pytest
@pytest.fixture
def existing_db():
database = Database(sqlite3.connect(":memory:"))
database.conn.executescript(
"""
CREATE TABLE foo (text TEXT);
INSERT INTO foo (text) values ("one");
INSERT INTO foo (text) values ("two");
INSERT INTO foo (text) values ("three");
"""
)
return database
def test_count(existing_db):
assert 3 == existing_db["foo"].count
def test_columns(existing_db):
table = existing_db["foo"]
assert [{"name": "text", "type": "TEXT"}] == [
{"name": col.name, "type": col.type} for col in table.columns
]