Skip to content

Commit

Permalink
Fix bug in slicing into container adapter (#635)
Browse files Browse the repository at this point in the history
* Test exporting container.

* Fix slicing bug
  • Loading branch information
danielballan authored Feb 5, 2024
1 parent 4248258 commit 0cf5edd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tiled/_tests/test_container_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import io

import h5py
import pandas
import pytest
Expand Down Expand Up @@ -61,3 +63,6 @@ async def test_hdf5(tmpdir):
tree(client)
client["h"]["x"].read()
client["h"]["g"]["y"].read()

buffer = io.BytesIO()
client.export(buffer, format="application/json")
12 changes: 12 additions & 0 deletions tiled/_tests/test_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Persistent stores are being developed externally to the tiled package.
"""
import base64
import io
from datetime import datetime

import awkward
Expand Down Expand Up @@ -433,3 +434,14 @@ async def test_bytes_in_metadata(tree):
assert value.startswith("data:application/octet-stream;base64,")
label, encoded = value.split(",", 1)
assert base64.b64decode(encoded) == b"raw_bytes"


@pytest.mark.asyncio
async def test_container_export(tree):
with Context.from_app(build_app(tree)) as context:
client = from_context(context)

a = client.create_container("a")
a.write_array([1, 2, 3], key="b")
buffer = io.BytesIO()
client.export(buffer, format="application/json")
4 changes: 2 additions & 2 deletions tiled/catalog/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class CatalogContainerAdapter(CatalogNodeAdapter):
async def keys_range(self, offset, limit):
if self.data_sources:
return (await self.get_adapter()).keys()[
offset : offset + limit # noqa: E203
offset : (offset + limit) if limit is not None else None # noqa: E203
]
statement = select(orm.Node.key).filter(orm.Node.ancestors == self.segments)
for condition in self.conditions:
Expand All @@ -840,7 +840,7 @@ async def keys_range(self, offset, limit):
async def items_range(self, offset, limit):
if self.data_sources:
return (await self.get_adapter()).items()[
offset : offset + limit # noqa: E203
offset : (offset + limit) if limit is not None else None # noqa: E203
]
statement = select(orm.Node).filter(orm.Node.ancestors == self.segments)
for condition in self.conditions:
Expand Down

0 comments on commit 0cf5edd

Please sign in to comment.