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.
This commit is contained in:
Simon Willison 2018-04-03 06:46:11 -07:00
commit dd0566ff8e
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52

View file

@ -2,6 +2,7 @@ from datasette.app import Datasette
import itertools import itertools
import os import os
import sqlite3 import sqlite3
import sys
import string import string
import tempfile import tempfile
import time import time
@ -142,3 +143,13 @@ CREATE VIEW simple_view AS
a=a, b=b, c=c, content=content a=a, b=b, c=c, content=content
) for a, b, c, content in generate_compound_rows(1001) ) 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]))