Skip to content

Commit

Permalink
E2E tests for import of item-level properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWilkie committed Oct 9, 2024
1 parent 4383b24 commit 9518954
Show file tree
Hide file tree
Showing 22 changed files with 8,531 additions and 23 deletions.
57 changes: 51 additions & 6 deletions e2e_tests/cli/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def assert_same_annotation_slot_name(
assert actual_annotation.slot_names == [base_slot]


def assert_same_item_level_properties(
expected_item_level_properties: List[Dict[str, str]],
actual_item_level_properties: List[Dict[str, str]],
) -> None:
"""
Ensures that all expected item-level properties are present in exported item-level properties
"""
for expected_item_level_property in expected_item_level_properties:
assert expected_item_level_property in actual_item_level_properties


def compare_annotations_export(
actual_annotations_dir: Path,
expected_annotations_dir: Path,
Expand Down Expand Up @@ -151,16 +162,28 @@ def compare_annotations_export(
actual_filename = get_actual_annotation_filename(
expected_filename, actual_annotation_files
)
expected_annotations: List[dt.Annotation] = parse_darwin_json(
Path(expected_annotation_files[expected_filename])
).annotations # type: ignore
actual_annotations: List[dt.Annotation] = parse_darwin_json(
Path(actual_annotation_files[actual_filename])
).annotations # type: ignore
expected_annotation_data: List[dt.Annotation] = parse_darwin_json(
Path(expected_annotation_files[expected_filename]) # type: ignore
)
expected_annotations = expected_annotation_data.annotations # type: ignore
expected_item_level_properties = (
expected_annotation_data.item_properties # type: ignore
)

actual_annotation_data: List[dt.Annotation] = parse_darwin_json(
Path(actual_annotation_files[actual_filename]) # type: ignore
)
actual_annotations = actual_annotation_data.annotations # type: ignore
actual_item_level_properties = (
actual_annotation_data.item_properties # type: ignore
)

delete_annotation_uuids(expected_annotations)
delete_annotation_uuids(actual_annotations)

assert_same_item_level_properties(
expected_item_level_properties, actual_item_level_properties
)
for expected_annotation in expected_annotations:
actual_annotation = find_matching_actual_annotation(
expected_annotation, actual_annotations
Expand Down Expand Up @@ -263,6 +286,28 @@ def test_annotation_classes_are_created_with_properties_on_import(
)


def test_import_existing_item_level_properties(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
run_import_test(
local_dataset,
config_values,
item_type="single_slotted",
annotations_subdir="image_annotations_with_item_level_properties",
)


def test_item_level_property_classes_are_created_on_import(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
run_import_test(
local_dataset,
config_values,
item_type="single_slotted",
annotations_subdir="image_new_annotations_with_item_level_properties",
)


def test_appending_annotations(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
Expand Down
16 changes: 13 additions & 3 deletions e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
setup_annotation_classes,
setup_datasets,
teardown_annotation_classes,
setup_item_level_properties,
teardown_item_level_properties,
teardown_tests,
)

Expand Down Expand Up @@ -54,13 +56,15 @@ def pytest_sessionstart(session: pytest.Session) -> None:

config = ConfigValues(server=server, api_key=api_key, team_slug=team_slug)
datasets = setup_datasets(config)
teardown_annotation_classes(
config, []
) # Ensure that there are no annotation classes before running tests
# Ensure that there are no annotation classes or item-level properties before running tests
teardown_annotation_classes(config, [])
teardown_item_level_properties(config, [])
annotation_classes = setup_annotation_classes(config)
item_level_properties = setup_item_level_properties(config)
# pytest.datasets = datasets
setattr(pytest, "datasets", datasets)
setattr(pytest, "annotation_classes", annotation_classes)
setattr(pytest, "item_level_properties", item_level_properties)
setattr(pytest, "config_values", config)
# Set the environment variables for running CLI arguments
environ["DARWIN_BASE_URL"] = server
Expand All @@ -83,6 +87,11 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
raise ValueError(
"Annotation classes were not created, so could not tear them down"
)
item_level_properties = pytest.item_level_properties
if item_level_properties is None:
raise ValueError(
"Item-level properties were not created, so could not tear them down"
)

server = session.config.cache.get("server", None)
api_key = session.config.cache.get("api_key", None)
Expand All @@ -100,6 +109,7 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
teardown_tests(config, datasets)
assert isinstance(annotation_classes, List)
teardown_annotation_classes(config, annotation_classes)
teardown_item_level_properties(config, item_level_properties)


@pytest.fixture(
Expand Down
Loading

0 comments on commit 9518954

Please sign in to comment.