Skip to content

Commit

Permalink
[DAR-3333][External] Import raster layer annotations even if classes …
Browse files Browse the repository at this point in the history
…are created or updated (#918)

* Always return  when fetching remote classes

* Unit tests

* More concise tests
  • Loading branch information
JBWilkie authored Aug 27, 2024
1 parent 00fd6a9 commit fe582c8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
2 changes: 2 additions & 0 deletions darwin/dataset/remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ def fetch_remote_classes(self, team_wide=False) -> List[Dict[str, Any]]:
cls["available"] = belongs_to_current_dataset
if team_wide or belongs_to_current_dataset:
classes_to_return.append(cls)
elif cls["annotation_types"] == ["raster_layer"]:
classes_to_return.append(cls)
return classes_to_return

def fetch_remote_attributes(self) -> List[Dict[str, Any]]:
Expand Down
6 changes: 4 additions & 2 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,10 @@ def _import_annotations(
)

if (
annotation_type not in remote_classes
or annotation_class.name not in remote_classes[annotation_type]
(
annotation_type not in remote_classes
or annotation_class.name not in remote_classes[annotation_type]
)
and annotation_type
!= "raster_layer" # We do not skip raster layers as they are always available.
):
Expand Down
73 changes: 73 additions & 0 deletions tests/darwin/dataset/remote_dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,79 @@ def test_fetches_files_with_commas(
)


@pytest.mark.usefixtures("file_read_write_test")
class TestFetchRemoteClasses:
def setup_method(self):
self.mock_classes = [
{
"name": "class1",
"datasets": [{"id": 1}],
"annotation_types": ["type1"],
},
{
"name": "class2",
"datasets": [{"id": 2}],
"annotation_types": ["type2"],
},
{
"name": "raster_class",
"datasets": [],
"annotation_types": ["raster_layer"],
},
]

def create_remote_dataset(
self, darwin_client, dataset_name, dataset_slug, team_slug_darwin_json_v2
):
return RemoteDatasetV2(
client=darwin_client,
team=team_slug_darwin_json_v2,
name=dataset_name,
slug=dataset_slug,
dataset_id=1,
)

@responses.activate
def test_fetch_remote_classes_team_wide(
self,
darwin_client: Client,
dataset_name: str,
dataset_slug: str,
team_slug_darwin_json_v2: str,
):
remote_dataset = self.create_remote_dataset(
darwin_client, dataset_name, dataset_slug, team_slug_darwin_json_v2
)
with patch.object(
remote_dataset.client,
"fetch_remote_classes",
return_value=self.mock_classes,
):
result = remote_dataset.fetch_remote_classes(team_wide=True)
assert len(result) == 3
assert any(cls["name"] == "raster_class" for cls in result)

@responses.activate
def test_fetch_remote_classes_local_to_dataset(
self,
darwin_client: Client,
dataset_name: str,
dataset_slug: str,
team_slug_darwin_json_v2: str,
):
remote_dataset = self.create_remote_dataset(
darwin_client, dataset_name, dataset_slug, team_slug_darwin_json_v2
)
with patch.object(
remote_dataset.client,
"fetch_remote_classes",
return_value=self.mock_classes,
):
result = remote_dataset.fetch_remote_classes(team_wide=False)
assert len(result) == 2
assert any(cls["name"] == "raster_class" for cls in result)


@pytest.fixture
def remote_dataset(
darwin_client: Client,
Expand Down

0 comments on commit fe582c8

Please sign in to comment.