Skip to content

Commit

Permalink
[DAR-4041][External] Add multi-file E2E tests (#931)
Browse files Browse the repository at this point in the history
* Added multi-file  E2E tests

* Import E2E tests for multi-file items

* Style improvements
  • Loading branch information
JBWilkie authored Oct 8, 2024
1 parent 51ff12c commit 25aff99
Show file tree
Hide file tree
Showing 11 changed files with 1,265 additions and 275 deletions.
339 changes: 202 additions & 137 deletions e2e_tests/cli/test_import.py

Large diffs are not rendered by default.

227 changes: 169 additions & 58 deletions e2e_tests/cli/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,41 @@
import zipfile


def test_push_mixed_filetypes(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
"""
Test pushing a directory of files containing various fileytypes:
- .jpg
- .png
- .mp4
- .dcm
- .pdf
"""
push_dir = Path(__file__).parents[1] / "data" / "push" / "mixed_filetypes.zip"
def extract_and_push(
push_dir, local_dataset, config_values, expected_push_dir, extra_args=""
):
with tempfile.TemporaryDirectory() as tmp_dir_str:
tmp_dir = Path(tmp_dir_str)
with zipfile.ZipFile(push_dir) as z:
z.extractall(tmp_dir)
result = run_cli_command(
f"darwin dataset push {local_dataset.name} {tmp_dir}/mixed_filetypes"
f"darwin dataset push {local_dataset.name} {tmp_dir}/{expected_push_dir} {extra_args}"
)
assert_cli(result, 0)
wait_until_items_processed(config_values, local_dataset.id)
items = list_items(
return list_items(
config_values.api_key,
local_dataset.id,
config_values.team_slug,
config_values.server,
)
assert len(items) == 5


def test_push_mixed_filetypes(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
"""
Test pushing a directory of files containing various fileytypes:
- .jpg
- .png
- .mp4
- .dcm
- .pdf
"""
expected_push_dir = "mixed_filetypes"
push_dir = Path(__file__).parents[1] / "data" / "push" / f"{expected_push_dir}.zip"
items = extract_and_push(push_dir, local_dataset, config_values, expected_push_dir)
assert len(items) == 5


def test_push_nested_directory_of_images(
Expand All @@ -49,6 +56,7 @@ def test_push_nested_directory_of_images(
"""
Test pushing a nested directory structure of some images with the `preserve_folders` flag.
"""
expected_push_dir = "nested_directory_of_images"
expected_paths = {
"image_1.jpg": "/dir1",
"image_2.jpg": "/dir1",
Expand All @@ -57,27 +65,13 @@ def test_push_nested_directory_of_images(
"image_5.jpg": "/dir1/dir3",
"image_6.jpg": "/dir1/dir3",
}
push_dir = (
Path(__file__).parents[1] / "data" / "push" / "nested_directory_of_images.zip"
push_dir = Path(__file__).parents[1] / "data" / "push" / f"{expected_push_dir}.zip"
items = extract_and_push(
push_dir, local_dataset, config_values, expected_push_dir, "--preserve-folders"
)
with tempfile.TemporaryDirectory() as tmp_dir_str:
tmp_dir = Path(tmp_dir_str)
with zipfile.ZipFile(push_dir) as z:
z.extractall(tmp_dir)
result = run_cli_command(
f"darwin dataset push {local_dataset.name} {tmp_dir}/nested_directory_of_images --preserve-folders"
)
assert_cli(result, 0)
wait_until_items_processed(config_values, local_dataset.id)
items = list_items(
config_values.api_key,
local_dataset.id,
config_values.team_slug,
config_values.server,
)
assert len(items) == 6
for item in items:
assert expected_paths[item["name"]] == item["path"]
assert len(items) == 6
for item in items:
assert expected_paths[item["name"]] == item["path"]


def test_push_videos_with_non_native_fps(
Expand All @@ -86,27 +80,144 @@ def test_push_videos_with_non_native_fps(
"""
Test that if FPS is set, that the value is respected in the resulting dataset items
"""
push_dir = Path(__file__).parents[1] / "data" / "push" / "25_frame_video.zip"
expected_push_dir = "25_frame_video"
push_dir = Path(__file__).parents[1] / "data" / "push" / f"{expected_push_dir}.zip"
fps = 5
with tempfile.TemporaryDirectory() as tmp_dir_str:
tmp_dir = Path(tmp_dir_str)
with zipfile.ZipFile(push_dir) as z:
z.extractall(tmp_dir)
result = run_cli_command(
f"darwin dataset push {local_dataset.name} {tmp_dir}/25_frame_video --fps {fps}"
)
assert_cli(result, 0)
wait_until_items_processed(config_values, local_dataset.id)
items = list_items(
config_values.api_key,
local_dataset.id,
config_values.team_slug,
config_values.server,
)
video_metadata = items[0]["slots"][0]["metadata"]
assert len(items) == 1
assert 1 == 1
assert items[0]["slots"][0]["fps"] == fps
assert video_metadata["native_fps"] == 10
assert video_metadata["frames_manifests"][0]["total_frames"] == 25
assert video_metadata["frames_manifests"][0]["visible_frames"] == 13
items = extract_and_push(
push_dir, local_dataset, config_values, expected_push_dir, f"--fps {fps}"
)
video_metadata = items[0]["slots"][0]["metadata"]
assert len(items) == 1
assert items[0]["slots"][0]["fps"] == fps
assert video_metadata["native_fps"] == 10
assert video_metadata["frames_manifests"][0]["total_frames"] == 25
assert video_metadata["frames_manifests"][0]["visible_frames"] == 13


def test_push_multi_slotted_item(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
"""
Test pushing a multi-slotted item with the CLI. Check the resulting item is
structured as expected
"""
expected_push_dir = "flat_directory_of_6_images"
expected_name = "flat_directory_of_6_images"
expected_slot_types = ["image", "image", "image", "image", "image", "image"]
expected_layout = {
"slots_grid": [[["0"], ["3"]], [["1"], ["4"]], [["2"], ["5"]]],
"version": 3,
}
expected_file_names = [
"image_1.jpg",
"image_2.jpg",
"image_3.jpg",
"image_4.jpg",
"image_5.jpg",
"image_6.jpg",
]
push_dir = Path(__file__).parents[1] / "data" / "push" / f"{expected_push_dir}.zip"
items = extract_and_push(
push_dir,
local_dataset,
config_values,
expected_push_dir,
"--item-merge-mode slots",
)
assert len(items) == 1
multi_slotted_item = items[0]
assert multi_slotted_item["name"] == expected_name
assert multi_slotted_item["slot_types"] == expected_slot_types
assert multi_slotted_item["layout"] == expected_layout
for num, slot in enumerate(multi_slotted_item["slots"]):
assert slot["slot_name"] == str(num)
assert slot["file_name"] == expected_file_names[num]


def test_push_multi_channel_item(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
"""
Test pushing a multi-channel item with the CLI. Check the resulting item is
structured as expected
"""
expected_push_dir = "flat_directory_of_6_images"
expected_name = "flat_directory_of_6_images"
expected_slot_types = ["image", "image", "image", "image", "image", "image"]
expected_layout = {
"slots_grid": [
[
[
"image_1.jpg",
"image_2.jpg",
"image_3.jpg",
"image_4.jpg",
"image_5.jpg",
"image_6.jpg",
]
]
],
"version": 3,
}
expected_file_names = [
"image_1.jpg",
"image_2.jpg",
"image_3.jpg",
"image_4.jpg",
"image_5.jpg",
"image_6.jpg",
]
push_dir = Path(__file__).parents[1] / "data" / "push" / f"{expected_push_dir}.zip"
items = extract_and_push(
push_dir,
local_dataset,
config_values,
expected_push_dir,
"--item-merge-mode channels",
)
assert len(items) == 1
multi_channel_item = items[0]
assert multi_channel_item["name"] == expected_name
assert multi_channel_item["slot_types"] == expected_slot_types
assert multi_channel_item["layout"] == expected_layout
for num, slot in enumerate(multi_channel_item["slots"]):
assert slot["slot_name"] == expected_file_names[num]
assert slot["file_name"] == expected_file_names[num]


def test_push_dicom_series(
local_dataset: E2EDataset, config_values: ConfigValues
) -> None:
"""
Test pushing a multi-file DICOM item with the CLI. Check the resulting item is
structured as expected
"""
expected_push_dir = "flat_directory_of_2_dicom_files"
expected_name = "flat_directory_of_2_dicom_files"
expected_slot_types = ["dicom", "dicom"]
expected_layout = {
"slots_grid": [
[
[
"flat_directory_of_2_dicom_files",
]
]
],
"version": 3,
}
expected_file_names = ["flat_directory_of_2_dicom_files"]
push_dir = Path(__file__).parents[1] / "data" / "push" / f"{expected_push_dir}.zip"
items = extract_and_push(
push_dir,
local_dataset,
config_values,
expected_push_dir,
"--item-merge-mode series",
)
assert len(items) == 1
dicom_series_item = items[0]
assert dicom_series_item["name"] == expected_name
assert dicom_series_item["slot_types"] == expected_slot_types
assert dicom_series_item["layout"] == expected_layout
for num, slot in enumerate(dicom_series_item["slots"]):
assert slot["slot_name"] == expected_file_names[num]
Loading

0 comments on commit 25aff99

Please sign in to comment.