Skip to content

Commit

Permalink
[GSoC2024] added filter to not include gt_job when the test intends t…
Browse files Browse the repository at this point in the history
…o create one. (#7623)

<!-- Raise an issue to propose your change
(https://github.com/opencv/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://opencv.github.io/cvat/docs/contributing/). -->
Fixes #7622 

Added a check to ensure that tests which need to create a gt_job aren't
picking up tasks which already have a gt_job


### How has this been tested?
I added a new task to the testing database and ran these updated tests.

### 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~
- [x] I have added tests to cover my changes
- [x] 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/opencv/cvat/tree/develop/cvat-canvas#versioning),

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

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

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

### License

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

---------

Co-authored-by: Maxim Zhiltsov <[email protected]>
  • Loading branch information
Viditagarwal7479 and zhiltsov-max authored Mar 21, 2024
1 parent d1a300f commit dd64046
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions tests/python/rest_api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _test_create_job_fails(
return response

@pytest.mark.parametrize("task_mode", ["annotation", "interpolation"])
def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, task_mode):
def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, jobs, task_mode):
user = admin_user
job_frame_count = 4
task = next(
Expand All @@ -90,6 +90,7 @@ def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, task_mode
and not t["organization"]
and t["mode"] == task_mode
and t["size"] > job_frame_count
and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth")
)
task_id = task["id"]
with make_api_client(user) as api_client:
Expand All @@ -116,7 +117,7 @@ def test_can_create_gt_job_with_manual_frames(self, admin_user, tasks, task_mode
assert job_frame_ids == gt_job_meta.included_frames

@pytest.mark.parametrize("task_mode", ["annotation", "interpolation"])
def test_can_create_gt_job_with_random_frames(self, admin_user, tasks, task_mode):
def test_can_create_gt_job_with_random_frames(self, admin_user, tasks, jobs, task_mode):
user = admin_user
job_frame_count = 3
required_task_frame_count = job_frame_count + 1
Expand All @@ -127,6 +128,7 @@ def test_can_create_gt_job_with_random_frames(self, admin_user, tasks, task_mode
and not t["organization"]
and t["mode"] == task_mode
and t["size"] > required_task_frame_count
and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth")
)
task_id = task["id"]

Expand Down Expand Up @@ -574,9 +576,13 @@ def test_get_gt_job_in_org_task(
"restore_db_per_class"
)
class TestGetGtJobData:
@pytest.mark.usefixtures("restore_db_per_function")

def _delete_gt_job(self, user, gt_job_id):
with make_api_client(user) as api_client:
api_client.jobs_api.destroy(gt_job_id)

@pytest.mark.parametrize("task_mode", ["annotation", "interpolation"])
def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode):
def test_can_get_gt_job_meta(self, admin_user, tasks, jobs, task_mode, request):
user = admin_user
job_frame_count = 4
task = next(
Expand All @@ -586,6 +592,7 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode):
and not t["organization"]
and t["mode"] == task_mode
and t["size"] > job_frame_count
and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth")
)
task_id = task["id"]
with make_api_client(user) as api_client:
Expand All @@ -595,11 +602,13 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode):
job_frame_ids = list(range(task_meta.start_frame, task_meta.stop_frame, frame_step))[
:job_frame_count
]
gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids)
gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids)

with make_api_client(user) as api_client:
(gt_job_meta, _) = api_client.jobs_api.retrieve_data_meta(gt_job.id)

request.addfinalizer(lambda: self._delete_gt_job(user, gt_job.id))

# These values are relative to the resulting task frames, unlike meta values
assert 0 == gt_job.start_frame
assert task_meta.size - 1 == gt_job.stop_frame
Expand All @@ -622,8 +631,7 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode):
else:
assert False

@pytest.mark.usefixtures("restore_db_per_function")
def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user):
def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user, request):
image_count = 50
start_frame = 3
stop_frame = image_count - 4
Expand All @@ -649,11 +657,13 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user):

task_frame_ids = range(start_frame, stop_frame, frame_step)
job_frame_ids = list(task_frame_ids[::3])
gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids)
gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids)

with make_api_client(admin_user) as api_client:
(gt_job_meta, _) = api_client.jobs_api.retrieve_data_meta(gt_job.id)

request.addfinalizer(lambda: self._delete_gt_job(admin_user, gt_job.id))

# These values are relative to the resulting task frames, unlike meta values
assert 0 == gt_job.start_frame
assert len(task_frame_ids) - 1 == gt_job.stop_frame
Expand All @@ -674,7 +684,7 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user):

@pytest.mark.parametrize("task_mode", ["annotation", "interpolation"])
@pytest.mark.parametrize("quality", ["compressed", "original"])
def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality):
def test_can_get_gt_job_chunk(self, admin_user, tasks, jobs, task_mode, quality, request):
user = admin_user
job_frame_count = 4
task = next(
Expand All @@ -684,6 +694,7 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality):
and not t["organization"]
and t["mode"] == task_mode
and t["size"] > job_frame_count
and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth")
)
task_id = task["id"]
with make_api_client(user) as api_client:
Expand All @@ -693,14 +704,16 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality):
job_frame_ids = list(range(task_meta.start_frame, task_meta.stop_frame, frame_step))[
:job_frame_count
]
gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids)
gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids)

with make_api_client(admin_user) as api_client:
(chunk_file, response) = api_client.jobs_api.retrieve_data(
gt_job.id, number=0, quality=quality, type="chunk"
)
assert response.status == HTTPStatus.OK

request.addfinalizer(lambda: self._delete_gt_job(admin_user, gt_job.id))

frame_range = range(
task_meta.start_frame, min(task_meta.stop_frame + 1, task_meta.chunk_size), frame_step
)
Expand All @@ -724,26 +737,29 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality):
assert image.size > (1, 1)
assert np.any(image_data != 0)

def _get_or_create_gt_job(self, user, task_id, frames):
def _create_gt_job(self, user, task_id, frames):
with make_api_client(user) as api_client:
(task_jobs, _) = api_client.jobs_api.list(task_id=task_id, type="ground_truth")
if task_jobs.results:
gt_job = task_jobs.results[0]
else:
job_spec = {
"task_id": task_id,
"type": "ground_truth",
"frame_selection_method": "manual",
"frames": frames,
}
job_spec = {
"task_id": task_id,
"type": "ground_truth",
"frame_selection_method": "manual",
"frames": frames,
}

(gt_job, _) = api_client.jobs_api.create(job_spec)

return gt_job

(gt_job, _) = api_client.jobs_api.create(job_spec)
def _get_gt_job(self, user, task_id):
with make_api_client(user) as api_client:
(task_jobs, _) = api_client.jobs_api.list(task_id=task_id, type="ground_truth")
gt_job = task_jobs.results[0]

return gt_job

@pytest.mark.parametrize("task_mode", ["annotation", "interpolation"])
@pytest.mark.parametrize("quality", ["compressed", "original"])
def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality):
def test_can_get_gt_job_frame(self, admin_user, tasks, jobs, task_mode, quality, request):
user = admin_user
job_frame_count = 4
task = next(
Expand All @@ -753,6 +769,7 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality):
and not t["organization"]
and t["mode"] == task_mode
and t["size"] > job_frame_count
and not any(j for j in jobs if j["task_id"] == t["id"] and j["type"] == "ground_truth")
)
task_id = task["id"]
with make_api_client(user) as api_client:
Expand All @@ -762,7 +779,7 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality):
job_frame_ids = list(range(task_meta.start_frame, task_meta.stop_frame, frame_step))[
:job_frame_count
]
gt_job = self._get_or_create_gt_job(admin_user, task_id, job_frame_ids)
gt_job = self._create_gt_job(admin_user, task_id, job_frame_ids)

frame_range = range(
task_meta.start_frame, min(task_meta.stop_frame + 1, task_meta.chunk_size), frame_step
Expand All @@ -787,6 +804,8 @@ def test_can_get_gt_job_frame(self, admin_user, tasks, task_mode, quality):
)
assert response.status == HTTPStatus.OK

request.addfinalizer(lambda: self._delete_gt_job(admin_user, gt_job.id))


@pytest.mark.usefixtures("restore_db_per_class")
class TestListJobs:
Expand Down

0 comments on commit dd64046

Please sign in to comment.