Skip to content

Commit

Permalink
Make data_sources a method, as it _may_ fetch now.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Feb 7, 2024
1 parent d96a276 commit d023d6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions tiled/_tests/test_asset_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ def test_include_data_sources_method_on_self(client):
client.write_array([1, 2, 3], key="x")
with pytest.warns(UserWarning):
# This fetches the sources with a second request.
client["x"].data_sources
client["x"].include_data_sources().data_sources is not None
client["x"].data_sources()
client["x"].include_data_sources().data_sources() is not None


def test_include_data_sources_method_affects_children(client):
"Calling include_data_sources() fetches data sources on children."
client.create_container("c")
client["c"].write_array([1, 2, 3], key="x")
c = client["c"].include_data_sources()
c["x"].data_sources is not None
c["x"].data_sources() is not None


def test_include_data_sources_kwarg(context):
"Passing include_data_sources to constructor includes them by default."
client = from_context(context, include_data_sources=True)
client.write_array([1, 2, 3], key="x")
client["x"].data_sources is not None
client["x"].data_sources() is not None
client["x"].include_data_sources() is not None


def test_raw_export(client, tmpdir):
"Use raw_export() and compare hashes or original and exported files."
client.write_array([1, 2, 3], key="x")
exported_paths = client["x"].raw_export(tmpdir)
data_sources = client["x"].include_data_sources().data_sources
data_sources = client["x"].include_data_sources().data_sources()
orig_dir = path_from_uri(data_sources[0]["assets"][0]["data_uri"])
_asset_id, relative_paths = client["x"].asset_manifests(data_sources).popitem()
orig_paths = [Path(orig_dir, relative_path) for relative_path in relative_paths]
Expand Down
10 changes: 8 additions & 2 deletions tiled/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ def structure_family(self):
"Quick access to this entry"
return StructureFamily[self.item["attributes"]["structure_family"]]

@property
def data_sources(self):
if not self._include_data_sources:
warnings.warn(
Expand Down Expand Up @@ -250,6 +249,13 @@ def asset_manifests(self, data_sources):
This return a dictionary keyed on asset ID.
Assets backed by a single file are mapped to None (no manifest).
Asset backed by a directory of files are mapped to a list of relative paths.
Parameters
----------
data_sources : dict
The value returned by ``.data_sources()``. This is passed in explicitly
to avoid fetching it twice in common usages. It also enables passing in
a subset of the data_sources of interest.
"""
manifests = {}
for data_source in data_sources:
Expand Down Expand Up @@ -296,7 +302,7 @@ def raw_export(self, directory=None, max_workers=4):

urls = []
paths = []
data_sources = self.include_data_sources().data_sources
data_sources = self.include_data_sources().data_sources()
asset_manifests = self.asset_manifests(data_sources)
if len(data_sources) != 1:
raise NotImplementedError(
Expand Down

0 comments on commit d023d6b

Please sign in to comment.