mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Initial project layout + database table creation tools
This commit is contained in:
parent
2f34da0ab2
commit
bd71be32ab
11 changed files with 458 additions and 0 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
40
tests/test_create.py
Normal file
40
tests/test_create.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from sqlite_utils import db
|
||||
import sqlite3
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fresh_db():
|
||||
return db.Database(sqlite3.connect(":memory:"))
|
||||
|
||||
|
||||
def test_create_table(fresh_db):
|
||||
assert [] == fresh_db.tables
|
||||
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 [
|
||||
{"name": "text_col", "type": "TEXT"},
|
||||
{"name": "float_col", "type": "FLOAT"},
|
||||
{"name": "int_col", "type": "INTEGER"},
|
||||
{"name": "bool_col", "type": "INTEGER"},
|
||||
] == [{"name": col.name, "type": col.type} for col in table.columns]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"example,expected_columns",
|
||||
(
|
||||
(
|
||||
{"name": "Ravi", "age": 63},
|
||||
[{"name": "name", "type": "TEXT"}, {"name": "age", "type": "INTEGER"}],
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_create_table_from_example(fresh_db, example, expected_columns):
|
||||
fresh_db["people"].insert(example)
|
||||
assert ["people"] == fresh_db.tables
|
||||
assert expected_columns == [
|
||||
{"name": col.name, "type": col.type} for col in fresh_db["people"].columns
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue