Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC2024] added filter to not include gt_job when the test intends to create one. #7623

Merged
merged 17 commits into from
Mar 21, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4f1666c
added filter to not include gt_job when the test intends to create one.
Viditagarwal7479 Mar 17, 2024
61f08f1
Merge branch 'develop' into tests_gt_job
Viditagarwal7479 Mar 17, 2024
2d85a43
added check to if specific frames are requested then there shouldn't …
Viditagarwal7479 Mar 18, 2024
b6b9052
restoring testing database to original state after each test
Viditagarwal7479 Mar 18, 2024
3fd9460
linted tests
Viditagarwal7479 Mar 18, 2024
e69a4d1
added request.addfinalizer to remove created gt_jobs
Viditagarwal7479 Mar 19, 2024
cb86895
Merge branch 'develop' into tests_gt_job
Viditagarwal7479 Mar 19, 2024
2a547c7
made testing db revert to original state after running TestGetGtJobData
Viditagarwal7479 Mar 19, 2024
eefa0f6
fixed linting
Viditagarwal7479 Mar 19, 2024
a903733
Merge branch 'develop' into tests_gt_job
Viditagarwal7479 Mar 20, 2024
40f1e96
reformatted function name of helper method
Viditagarwal7479 Mar 20, 2024
4d54ed4
Merge remote-tracking branch 'origin/tests_gt_job' into tests_gt_job
Viditagarwal7479 Mar 20, 2024
33af1b7
split the get and create gt job function into two separate functions …
Viditagarwal7479 Mar 20, 2024
88bb859
refactored the name change of delete gt job method
Viditagarwal7479 Mar 20, 2024
1d9e2a4
removed raised warnings depened on the presence of gt_job in task
Viditagarwal7479 Mar 20, 2024
109c8a9
removed the unwanted job list call while creating a gt_job
Viditagarwal7479 Mar 20, 2024
de646ad
Apply suggestions from code review
zhiltsov-max Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading