.table_names and .tables properties plus expanded docs

This commit is contained in:
Simon Willison 2018-07-31 17:35:36 -07:00
commit 515d362ad6
5 changed files with 54 additions and 11 deletions

View file

@ -4,12 +4,12 @@ import json
def test_create_table(fresh_db):
assert [] == fresh_db.tables
assert [] == fresh_db.table_names
table = fresh_db.create_table(
"test_table",
{"text_col": str, "float_col": float, "int_col": int, "bool_col": bool},
)
assert ["test_table"] == fresh_db.tables
assert ["test_table"] == fresh_db.table_names
assert [
{"name": "text_col", "type": "TEXT"},
{"name": "float_col", "type": "FLOAT"},
@ -29,7 +29,7 @@ def test_create_table(fresh_db):
)
def test_create_table_from_example(fresh_db, example, expected_columns):
fresh_db["people"].insert(example)
assert ["people"] == fresh_db.tables
assert ["people"] == fresh_db.table_names
assert expected_columns == [
{"name": col.name, "type": col.type} for col in fresh_db["people"].columns
]

View file

@ -10,7 +10,7 @@ search_records = [
def test_enable_fts(fresh_db):
table = fresh_db["searchable"]
table.insert_all(search_records)
assert ["searchable"] == fresh_db.tables
assert ["searchable"] == fresh_db.table_names
table.enable_fts(["text", "country"])
assert [
"searchable",
@ -19,7 +19,7 @@ def test_enable_fts(fresh_db):
"searchable_fts_segdir",
"searchable_fts_docsize",
"searchable_fts_stat",
] == fresh_db.tables
] == fresh_db.table_names
assert [("tanuki are tricksters", "Japan", "foo")] == table.search("tanuki")
assert [("racoons are trash pandas", "USA", "bar")] == table.search("usa")
assert [] == table.search("bar")

View file

@ -1,6 +1,15 @@
from .fixtures import existing_db
def test_table_names(existing_db):
assert ["foo"] == existing_db.table_names
def test_tables(existing_db):
assert 1 == len(existing_db.tables)
assert "foo" == existing_db.tables[0].name
def test_count(existing_db):
assert 3 == existing_db["foo"].count
@ -14,3 +23,7 @@ def test_columns(existing_db):
def test_schema(existing_db):
assert "CREATE TABLE foo (text TEXT)" == existing_db["foo"].schema
def test_table_repr(existing_db):
assert "<Table foo>" == repr(existing_db["foo"])