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 10 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
37 changes: 29 additions & 8 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,17 @@ 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):
Viditagarwal7479 marked this conversation as resolved.
Show resolved Hide resolved
with make_api_client(user) as api_client:
(_, gt_job_del_response) = api_client.jobs_api.destroy(gt_job_id)
assert (
gt_job_del_response.status == HTTPStatus.NO_CONTENT
), "newly created gt_job couldn't be deleted"
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved

# @pytest.fixture
Viditagarwal7479 marked this conversation as resolved.
Show resolved Hide resolved
@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 +596,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 @@ -600,6 +611,8 @@ def test_can_get_gt_job_meta(self, admin_user, tasks, task_mode):
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))
Viditagarwal7479 marked this conversation as resolved.
Show resolved Hide resolved

# 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 +635,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 Down Expand Up @@ -654,6 +666,8 @@ def test_can_get_gt_job_meta_with_complex_frame_setup(self, admin_user):
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 +688,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 +698,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 @@ -701,6 +716,8 @@ def test_can_get_gt_job_chunk(self, admin_user, tasks, task_mode, quality):
)
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 Down Expand Up @@ -728,6 +745,7 @@ def _get_or_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:
assert not frames, "specific frames requested but gt_job exists"
Viditagarwal7479 marked this conversation as resolved.
Show resolved Hide resolved
gt_job = task_jobs.results[0]
else:
job_spec = {
Expand All @@ -743,7 +761,7 @@ def _get_or_create_gt_job(self, user, task_id, frames):

@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 +771,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 Down Expand Up @@ -787,6 +806,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