Skip to content

Commit

Permalink
Check creating task with advanced params with file from cloud data (#…
Browse files Browse the repository at this point in the history
…8014)

<!-- Raise an issue to propose your change
(https://github.com/cvat-ai/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution guide](https://docs.cvat.ai/docs/contributing/).
-->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->
Test for #7969
### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [ ] I have created a changelog fragment <!-- see top comment in
CHANGELOG.md -->
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [ ] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/cvat-ai/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/cvat-ai/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/cvat-ai/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/cvat-ai/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Tests**
- Added tests for data retrieval and frame information in the REST API.
  - Updated test logic to handle video file generation and removal.
- Enhanced test utility function to support additional specifications
for tasks.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Boris Sekachev <boris.sekachev@yandex.ru>
  • Loading branch information
novda and bsekachev committed Jul 2, 2024
1 parent 84dde61 commit fb0eb43
Showing 1 changed file with 76 additions and 15 deletions.
91 changes: 76 additions & 15 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pathlib import Path
from tempfile import NamedTemporaryFile, TemporaryDirectory
from time import sleep, time
from typing import Any, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple

import pytest
from cvat_sdk import Client, Config, exceptions
Expand Down Expand Up @@ -1332,30 +1332,48 @@ def _create_task_with_cloud_data(
server_files: List[str],
use_cache: bool = True,
sorting_method: str = "lexicographical",
spec: Optional[Dict[str, Any]] = None,
data_type: str = "image",
video_frame_count: int = 10,
server_files_exclude: Optional[List[str]] = None,
org: Optional[str] = None,
filenames: Optional[List[str]] = None,
) -> Tuple[int, Any]:
s3_client = s3.make_client()
images = generate_image_files(
3, **({"prefixes": ["img_"] * 3} if not filenames else {"filenames": filenames})
)

for image in images:
for i in range(2):
image.seek(0)
s3_client.create_file(
data=image,
if data_type == "video":
video = generate_video_file(video_frame_count)
s3_client.create_file(
data=video,
bucket=cloud_storage["resource"],
filename=f"test/video/{video.name}",
)
request.addfinalizer(
partial(
s3_client.remove_file,
bucket=cloud_storage["resource"],
filename=f"test/sub_{i}/{image.name}",
filename=f"test/video/{video.name}",
)
request.addfinalizer(
partial(
s3_client.remove_file,
)
else:
images = generate_image_files(
3, **({"prefixes": ["img_"] * 3} if not filenames else {"filenames": filenames})
)

for image in images:
for i in range(2):
image.seek(0)
s3_client.create_file(
data=image,
bucket=cloud_storage["resource"],
filename=f"test/sub_{i}/{image.name}",
)
)
request.addfinalizer(
partial(
s3_client.remove_file,
bucket=cloud_storage["resource"],
filename=f"test/sub_{i}/{image.name}",
)
)

if use_manifest:
with TemporaryDirectory() as tmp_dir:
Expand Down Expand Up @@ -1400,6 +1418,9 @@ def _create_task_with_cloud_data(
),
"sorting_method": sorting_method,
}
if spec is not None:
data_spec.update(spec)

if server_files_exclude:
data_spec["server_files_exclude"] = server_files_exclude

Expand Down Expand Up @@ -1743,6 +1764,46 @@ def test_create_task_with_cloud_storage_and_check_data_sorting(
for image_name, frame in zip(filenames, data_meta.frames):
assert frame.name.rsplit("/", maxsplit=1)[1] == image_name

@pytest.mark.with_external_services
@pytest.mark.parametrize(
"cloud_storage_id, org",
[
(1, ""),
],
)
def test_create_task_with_cloud_storage_and_check_retrieve_data_meta(
self,
cloud_storage_id: int,
org: str,
cloud_storages,
request,
):
cloud_storage = cloud_storages[cloud_storage_id]

data_spec = {
"start_frame": 2,
"stop_frame": 6,
"frame_filter": "step=2",
}

task_id, _ = self._create_task_with_cloud_data(
request=request,
cloud_storage=cloud_storage,
use_manifest=False,
use_cache=False,
server_files=["test/video/video.avi"],
org=org,
spec=data_spec,
data_type="video",
)

with make_api_client(self._USERNAME) as api_client:
data_meta, _ = api_client.tasks_api.retrieve_data_meta(task_id)

assert data_meta.start_frame == 2
assert data_meta.stop_frame == 6
assert data_meta.size == 3

def test_can_specify_file_job_mapping(self):
task_spec = {
"name": f"test file-job mapping",
Expand Down

0 comments on commit fb0eb43

Please sign in to comment.