Skip to content

Commit

Permalink
Add test for label properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Draga Doncila Pop committed Nov 20, 2020
1 parent 59c031e commit 391545c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ome_zarr/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ def create_zarr(
write_multiscale(labels, label_grp)

colors = []
properties = []
for x in range(1, 9):
rgba = [randrange(0, 256) for i in range(4)]
colors.append({"label-value": x, "rgba": rgba})
properties.append({"label-value": x, "class": f"class {x}"})
label_grp.attrs["image-label"] = {
"version": "0.1",
"colors": colors,
"properties": properties,
"source": {"image": "../../"},
}
10 changes: 8 additions & 2 deletions tests/test_napari.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initdir(self, tmpdir):
self.path = tmpdir.mkdir("data")
create_zarr(str(self.path), astronaut, "astronaut")

def assert_layers(self, layers, visible_1, visible_2):
def assert_layers(self, layers, visible_1, visible_2, label_props=None):
# TODO: check name

assert len(layers) == 2
Expand All @@ -27,6 +27,8 @@ def assert_layers(self, layers, visible_1, visible_2):

data, metadata, layer_type = self.assert_layer(label)
assert visible_2 == metadata["visible"]
if label_props:
assert label_props == metadata["properties"]

def assert_layer(self, layer_data):
data, metadata, layer_type = layer_data
Expand All @@ -47,7 +49,11 @@ def test_labels(self):
def test_label(self):
filename = str(self.path.join("labels", "astronaut"))
layers = napari_get_reader(filename)()
self.assert_layers(layers, False, True)
properties = {
"index": [i for i in range(1, 9)],
"class": [f"class {i}" for i in range(1, 9)],
}
self.assert_layers(layers, False, True, properties)

@pytest.mark.skipif(
not sys.platform.startswith("darwin") or sys.version_info < (3, 7),
Expand Down

0 comments on commit 391545c

Please sign in to comment.