X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=blobdiff_plain;f=tests%2Ffixtures.py;fp=tests%2Ffixtures.py;h=4c12d5502f8429a622c03c99868d80e74abf5207;hp=6093bda0ea7321d8dc7cf2e24df8dd71a919271b;hb=0cd020af033fcb2a15fe3326f3a49830b816379c;hpb=4798b85f3b904367fa8be0e67552440d3568afcb diff --git a/tests/fixtures.py b/tests/fixtures.py index 6093bda..4c12d55 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,28 +1,17 @@ from datasette_connectors import monkey; monkey.patch_datasette() -from datasette_connectors import connectors; connectors.load() +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): @@ -57,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