X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=blobdiff_plain;f=tests%2Ffixtures.py;h=4c12d5502f8429a622c03c99868d80e74abf5207;hp=417eb630e723a51cbfa7f8c5567ad9298071e6e2;hb=HEAD;hpb=6e41ba82816a32b30e077b49cae55a01a1da9dc5 diff --git a/tests/fixtures.py b/tests/fixtures.py index 417eb63..4c12d55 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,25 +1,17 @@ +from datasette_connectors import monkey; monkey.patch_datasette() +from datasette_connectors.connectors import ConnectorList +from datasette_pytables import PyTablesConnector +ConnectorList.add_connector('pytables', PyTablesConnector) + from datasette.app import Datasette +from datasette.utils.testing import TestClient import numpy as np import os import pytest from tables import * import tempfile +import contextlib -@pytest.fixture(scope='session') -def app_client(max_returned_rows=None): - with tempfile.TemporaryDirectory() as tmpdir: - filepath = os.path.join(tmpdir, 'test_tables.h5') - populate_file(filepath) - ds = Datasette( - [filepath], - config={ - 'default_page_size': 50, - 'max_returned_rows': max_returned_rows or 1000, - } - ) - client = ds.app().test_client - client.ds = ds - yield client def populate_file(filepath): class Particle(IsDescription): @@ -54,3 +46,45 @@ def populate_file(filepath): table.flush() h5file.close() + + +@contextlib.contextmanager +def make_app_client( + max_returned_rows=None, + config=None, + is_immutable=False, +): + with tempfile.TemporaryDirectory() as tmpdir: + filepath = os.path.join(tmpdir, 'test_tables.h5') + populate_file(filepath) + if is_immutable: + files = [] + immutables = [filepath] + else: + files = [filepath] + immutables = [] + config = config or {} + config.update({ + 'default_page_size': 50, + 'max_returned_rows': max_returned_rows or 1000, + }) + ds = Datasette( + files, + immutables=immutables, + config=config, + ) + client = TestClient(ds.app()) + client.ds = ds + yield client + + +@pytest.fixture(scope='session') +def app_client(): + with make_app_client() as client: + yield client + + +@pytest.fixture(scope='session') +def app_client_with_hash(): + with make_app_client(config={"hash_urls": True}, is_immutable=True) as client: + yield client