Skip to content

Commit

Permalink
tests: adjust tests for new changes in geojson format in 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-- committed Sep 6, 2022
1 parent 11e746a commit a6f6d06
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions paquo/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid
from copy import deepcopy
from functools import partial
from typing import List
from typing import Type
Expand Down Expand Up @@ -173,24 +175,70 @@ def test_geojson_roundtrip_via_geojson(empty_hierarchy):
}]


# qupath version v0.4.0 made changes to the geojson format
# 1. the 'id' key is added again but seems to be a UUID for each annotation
TEST_ANNOTATION_POLYGON_VERSION_0_4_0_snapshot = [{
'type': 'Feature',
'id': '7d254d72-a9a0-43a6-a455-3fa99e83b7af',
'geometry': {
'type': 'Polygon',
'coordinates': [[
[1000, 1300],
[1011, 1420],
[1120, 1430],
[1060, 1380],
[1000, 1300],
]]
},
'properties': {
'classification': {
'name': 'Tumor',
'colorRGB': -3670016
},
'isLocked': False,
'object_type': 'annotation',
}
}]


@pytest.fixture
def example_annotation(qupath_version):
if qupath_version <= QuPathVersion("0.2.3"):
yield TEST_ANNOTATION_POLYGON_VERSION_0_2_3
yield deepcopy(TEST_ANNOTATION_POLYGON_VERSION_0_2_3)
elif qupath_version < QuPathVersion("0.4.0"):
yield deepcopy(TEST_ANNOTATION_POLYGON_VERSION_0_3_0_rc1_plus)
else:
yield deepcopy(TEST_ANNOTATION_POLYGON_VERSION_0_4_0_snapshot)


def is_uuid(x):
try:
uuid.UUID(x)
except ValueError:
return False
else:
yield TEST_ANNOTATION_POLYGON_VERSION_0_3_0_rc1_plus
return True


@pytest.mark.parametrize(
"input_annotation", [
pytest.param(TEST_ANNOTATION_POLYGON_VERSION_0_2_3, id='v0.2.3'),
pytest.param(TEST_ANNOTATION_POLYGON_VERSION_0_3_0_rc1_plus, id='v0.3.0rc1')
pytest.param(TEST_ANNOTATION_POLYGON_VERSION_0_3_0_rc1_plus, id='v0.3.0rc1'),
pytest.param(TEST_ANNOTATION_POLYGON_VERSION_0_4_0_snapshot, id='v0.4.0+snapshot'),
]
)
def test_geojson_roundtrip_via_annotations(empty_hierarchy, example_annotation, input_annotation):
def test_geojson_roundtrip_via_annotations(empty_hierarchy, example_annotation, input_annotation, qupath_version):
h = empty_hierarchy
assert h.load_geojson(input_annotation)
output = h.to_geojson()

if qupath_version < QuPathVersion("0.4.0"):
pass
else:
# these uuids are assigned randomly if they were missing in input
out_id = output[0].pop("id", "")
test_id = example_annotation[0].pop("id", "")
assert is_uuid(out_id) and is_uuid(test_id)
assert output == example_annotation


Expand Down

0 comments on commit a6f6d06

Please sign in to comment.