+
+
+@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