From dd0566ff8eda7fa2f0d92e51809581fae62cffed Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 3 Apr 2018 06:46:11 -0700 Subject: [PATCH] Utility for writing test database fixtures to a .db file python tests/fixtures.py /tmp/hello.db This is useful for making a SQLite database of the test fixtures for interactive exploration. --- tests/fixtures.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/fixtures.py b/tests/fixtures.py index 0c79480a..cf19fa31 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -2,6 +2,7 @@ from datasette.app import Datasette import itertools import os import sqlite3 +import sys import string import tempfile import time @@ -142,3 +143,13 @@ CREATE VIEW simple_view AS a=a, b=b, c=c, content=content ) for a, b, c, content in generate_compound_rows(1001) ]) + + +if __name__ == '__main__': + filename = sys.argv[-1] + if filename.endswith('.db'): + conn = sqlite3.connect(filename) + conn.executescript(TABLES) + print('Test tables written to {}'.format(filename)) + else: + print('Usage: {} name_of_file_to_write.db'.format(sys.argv[0]))