table.count property, plus made a start on table documentation

This commit is contained in:
Simon Willison 2018-07-30 20:24:35 -07:00
commit b69f8b6c85
4 changed files with 80 additions and 1 deletions

28
tests/test_introspect.py Normal file
View file

@ -0,0 +1,28 @@
from sqlite_utils import db
import sqlite3
import pytest
@pytest.fixture
def existing_db():
database = db.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
]