From c446e22f34eb56a454c57edf93824d2615b83c0e Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 31 Jul 2018 08:55:24 -0700 Subject: [PATCH] Moved fixtures to fixtures.py, added .schema test --- tests/fixtures.py | 22 ++++++++++++++++++++++ tests/test_create.py | 10 ++-------- tests/test_introspect.py | 22 +++++----------------- 3 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 tests/fixtures.py diff --git a/tests/fixtures.py b/tests/fixtures.py new file mode 100644 index 0000000..322d627 --- /dev/null +++ b/tests/fixtures.py @@ -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 diff --git a/tests/test_create.py b/tests/test_create.py index 876d2a1..3fe6f5b 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -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): diff --git a/tests/test_introspect.py b/tests/test_introspect.py index d791865..de2d7df 100644 --- a/tests/test_introspect.py +++ b/tests/test_introspect.py @@ -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