X-Git-Url: https://git.jsancho.org/?p=datasette-pytables.git;a=blobdiff_plain;f=tests%2Ffixtures.py;h=4c12d5502f8429a622c03c99868d80e74abf5207;hp=bbca1186aefebe2c86704801d373a5b5d2aada96;hb=54aeb4a8918f31b273875646d7a56a1c4da34564;hpb=d411de8cb97045c9b7e51dec6182a89edef2701d diff --git a/tests/fixtures.py b/tests/fixtures.py index bbca118..4c12d55 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,22 +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 -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): @@ -37,6 +32,8 @@ def populate_file(filepath): array2 = h5file.create_array(group1, 'array2', [x for x in range(10000)]) + multiarray = h5file.create_array(group2, 'multi', np.arange(1000).reshape(10, 50, 2)) + for table in (table1, table2): row = table.row @@ -49,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