Moved fixtures to fixtures.py, added .schema test

This commit is contained in:
Simon Willison 2018-07-31 08:55:24 -07:00
commit c446e22f34
3 changed files with 29 additions and 25 deletions

22
tests/fixtures.py Normal file
View file

@ -0,0 +1,22 @@
from sqlite_utils import Database
import sqlite3
import pytest
@pytest.fixture
def fresh_db():
return Database(sqlite3.connect(":memory:"))
@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

View file

@ -1,12 +1,6 @@
from sqlite_utils import Database
import json
import sqlite3
from .fixtures import fresh_db
import pytest
@pytest.fixture
def fresh_db():
return Database(sqlite3.connect(":memory:"))
import json
def test_create_table(fresh_db):

View file

@ -1,20 +1,4 @@
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
from .fixtures import existing_db
def test_count(existing_db):
@ -26,3 +10,7 @@ def test_columns(existing_db):
assert [{"name": "text", "type": "TEXT"}] == [
{"name": col.name, "type": col.type} for col in table.columns
]
def test_schema(existing_db):
assert "CREATE TABLE foo (text TEXT)" == existing_db["foo"].schema