Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max committed Oct 2, 2024
1 parent 7f68cce commit b25e5e8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 5 deletions.
69 changes: 64 additions & 5 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ def test_create_task_with_cloud_storage_directories_and_default_bucket_prefix(
)
def test_can_create_task_with_honeypots(
self,
request: pytest.FixtureRequest,
fxt_test_name,
frame_selection_method: str,
method_params: Set[str],
per_job_count_param: str,
Expand Down Expand Up @@ -2170,7 +2170,7 @@ def test_can_create_task_with_honeypots(
assert False

task_params = {
"name": request.node.name,
"name": fxt_test_name,
"labels": [{"name": "a"}],
"segment_size": base_segment_size,
}
Expand Down Expand Up @@ -2238,6 +2238,63 @@ def test_can_create_task_with_honeypots(
== validation_per_job_count
)

@pytest.mark.parametrize("random_seed", [1, 2, 5])
def test_can_create_task_with_honeypots_random_seed_guarantees_the_same_layout(
self, fxt_test_name, random_seed: int
):
base_segment_size = 4
total_frame_count = 15
validation_frames_count = 5
validation_per_job_count = 2

image_files = generate_image_files(total_frame_count)

validation_params = {
"mode": "gt_pool",
"frame_selection_method": "random_uniform",
"frame_count": validation_frames_count,
"frames_per_job_count": validation_per_job_count,
"random_seed": random_seed,
}

task_params = {
"name": fxt_test_name,
"labels": [{"name": "a"}],
"segment_size": base_segment_size,
}

data_params = {
"image_quality": 70,
"client_files": image_files,
"sorting_method": "random",
"validation_params": validation_params,
}

def _create_task():
with make_api_client(self._USERNAME) as api_client:
task_id, _ = create_task(
self._USERNAME, spec=deepcopy(task_params), data=deepcopy(data_params)
)
task_meta = json.loads(api_client.tasks_api.retrieve_data_meta(task_id)[1].data)
task_validation_layout = json.loads(
api_client.tasks_api.retrieve_validation_layout(task_id)[1].data
)
return task_meta, task_validation_layout

task1_meta, task1_validation_layout = _create_task()
task2_meta, task2_validation_layout = _create_task()

assert (
DeepDiff(
task1_meta,
task2_meta,
ignore_order=False,
exclude_regex_paths=[r"root\['chunks_updated_date'\]"], # must be different
)
== {}
)
assert DeepDiff(task1_validation_layout, task2_validation_layout, ignore_order=False) == {}

@parametrize(
"frame_selection_method, method_params",
[
Expand Down Expand Up @@ -2630,11 +2687,12 @@ def _uploaded_images_task_with_honeypots_and_segments_base(
*,
start_frame: Optional[int] = None,
step: Optional[int] = None,
random_seed: int = 42,
) -> Generator[Tuple[_TaskSpec, int], None, None]:
validation_params = models.DataRequestValidationParams._from_openapi_data(
mode="gt_pool",
frame_selection_method="random_uniform",
random_seed=42,
random_seed=random_seed,
frame_count=5,
frames_per_job_count=2,
)
Expand Down Expand Up @@ -2705,12 +2763,13 @@ def fxt_uploaded_images_task_with_honeypots_and_segments_start_step(
)

@fixture(scope="class")
@parametrize("random_seed", [1, 2, 5])
def fxt_uploaded_images_task_with_honeypots_and_changed_real_frames(
self, request: pytest.FixtureRequest
self, request: pytest.FixtureRequest, random_seed: int
) -> Generator[Tuple[_TaskSpec, int], None, None]:
with closing(
self._uploaded_images_task_with_honeypots_and_segments_base(
request, start_frame=2, step=3
request, start_frame=2, step=3, random_seed=random_seed
)
) as gen_iter:
task_spec, task_id = next(gen_iter)
Expand Down
9 changes: 9 additions & 0 deletions tests/python/shared/fixtures/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ def fxt_logger():
logger.propagate = False
logger.addHandler(logging.StreamHandler(logger_stream))
yield logger, logger_stream


@pytest.fixture
def fxt_test_name(request: pytest.FixtureRequest):
name = request.node.name
if request.fixturename:
name += f"[{request.fixturename}]"

yield name

0 comments on commit b25e5e8

Please sign in to comment.