Skip to content

Commit

Permalink
Merge branch 'develop' into kl/hp-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov authored Nov 7, 2024
2 parents 3cbc27c + a56e94b commit bff7d9a
Show file tree
Hide file tree
Showing 31 changed files with 185 additions and 204 deletions.
4 changes: 1 addition & 3 deletions tests/python/cli/example_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: MIT

from typing import List

import cvat_sdk.auto_annotation as cvataa
import cvat_sdk.models as models
import PIL.Image
Expand All @@ -17,7 +15,7 @@

def detect(
context: cvataa.DetectionFunctionContext, image: PIL.Image.Image
) -> List[models.LabeledShapeRequest]:
) -> list[models.LabeledShapeRequest]:
return [
cvataa.rectangle(0, [1, 2, 3, 4]),
]
3 changes: 1 addition & 2 deletions tests/python/cli/example_parameterized_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: MIT

from types import SimpleNamespace as namespace
from typing import List

import cvat_sdk.auto_annotation as cvataa
import cvat_sdk.models as models
Expand All @@ -24,7 +23,7 @@ def create(s: str, i: int, f: float, b: bool) -> cvataa.DetectionFunction:

def detect(
context: cvataa.DetectionFunctionContext, image: PIL.Image.Image
) -> List[models.LabeledShapeRequest]:
) -> list[models.LabeledShapeRequest]:
return [
cvataa.rectangle(0, [1, 2, 3, 4]),
]
Expand Down
7 changes: 4 additions & 3 deletions tests/python/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import ssl
import threading
import unittest
from collections.abc import Generator
from pathlib import Path
from typing import Any, Dict, Generator, List, Union
from typing import Any, Union

import requests

Expand All @@ -28,7 +29,7 @@ def run_cli(test: Union[unittest.TestCase, Any], *args: str, expected_code: int
assert expected_code == main(args)


def generate_images(dst_dir: Path, count: int) -> List[Path]:
def generate_images(dst_dir: Path, count: int) -> list[Path]:
filenames = []
dst_dir.mkdir(parents=True, exist_ok=True)
for i in range(count):
Expand Down Expand Up @@ -70,7 +71,7 @@ def do_POST(self):
response = requests.post(data=self.rfile.read(body_length), **self._shared_request_args())
self._translate_response(response)

def _shared_request_args(self) -> Dict[str, Any]:
def _shared_request_args(self) -> dict[str, Any]:
headers = {k.lower(): v for k, v in self.headers.items()}
del headers["host"]

Expand Down
4 changes: 2 additions & 2 deletions tests/python/rest_api/test_analytics_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json
from http import HTTPStatus
from typing import Any, Dict, Optional
from typing import Any, Optional

import pytest
from cvat_sdk.api_client import models
Expand Down Expand Up @@ -67,7 +67,7 @@ def _test_get_report_200(
job_id: Optional[int] = None,
task_id: Optional[int] = None,
project_id: Optional[int] = None,
expected_data: Optional[Dict[str, Any]] = None,
expected_data: Optional[dict[str, Any]] = None,
**kwargs,
):
params = self._get_query_params(job_id=job_id, task_id=task_id, project_id=project_id)
Expand Down
4 changes: 2 additions & 2 deletions tests/python/rest_api/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
from copy import deepcopy
from http import HTTPStatus
from typing import Any, Dict, List, Tuple
from typing import Any

import pytest
from cvat_sdk import models
Expand Down Expand Up @@ -367,7 +367,7 @@ def setup(self, restore_db_per_class, admin_user, comments, issues):
def _get_endpoint(self, api_client: ApiClient) -> Endpoint:
return api_client.comments_api.list_endpoint

def _get_field_samples(self, field: str) -> Tuple[Any, List[Dict[str, Any]]]:
def _get_field_samples(self, field: str) -> tuple[Any, list[dict[str, Any]]]:
if field == "job_id":
issue_id, issue_comments = super()._get_field_samples("issue_id")
issue = next((s for s in self.sample_issues if s["id"] == issue_id))
Expand Down
16 changes: 8 additions & 8 deletions tests/python/rest_api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from http import HTTPStatus
from io import BytesIO
from itertools import groupby, product
from typing import Any, Dict, List, Optional, Set, Tuple, Union
from typing import Any, Optional, Union

import numpy as np
import pytest
Expand Down Expand Up @@ -71,7 +71,7 @@ def filter_jobs(jobs, tasks, org):

@pytest.mark.usefixtures("restore_db_per_function")
class TestPostJobs:
def _test_create_job_ok(self, user: str, data: Dict[str, Any], **kwargs):
def _test_create_job_ok(self, user: str, data: dict[str, Any], **kwargs):
with make_api_client(user) as api_client:
(_, response) = api_client.jobs_api.create(
models.JobWriteRequest(**deepcopy(data)), **kwargs
Expand All @@ -80,7 +80,7 @@ def _test_create_job_ok(self, user: str, data: Dict[str, Any], **kwargs):
return response

def _test_create_job_fails(
self, user: str, data: Dict[str, Any], *, expected_status: int, **kwargs
self, user: str, data: dict[str, Any], *, expected_status: int, **kwargs
):
with make_api_client(user) as api_client:
(_, response) = api_client.jobs_api.create(
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_can_create_gt_job_in_a_task(
tasks,
task_mode: str,
frame_selection_method: str,
method_params: Set[str],
method_params: set[str],
):
required_task_size = 15

Expand Down Expand Up @@ -544,7 +544,7 @@ def test_destroy_gt_job_in_org_task(
@pytest.mark.usefixtures("restore_db_per_class")
class TestGetJobs:
def _test_get_job_200(
self, user, jid, *, expected_data: Optional[Dict[str, Any]] = None, **kwargs
self, user, jid, *, expected_data: Optional[dict[str, Any]] = None, **kwargs
):
with make_api_client(user) as client:
(_, response) = client.jobs_api.retrieve(jid, **kwargs)
Expand Down Expand Up @@ -1442,7 +1442,7 @@ def _test_export_dataset(
username: str,
jid: int,
*,
api_version: Union[int, Tuple[int]],
api_version: Union[int, tuple[int]],
local_download: bool = True,
**kwargs,
) -> Optional[bytes]:
Expand Down Expand Up @@ -1473,9 +1473,9 @@ def _test_export_annotations(
def test_can_export_dataset_locally_and_to_cloud_with_both_api_versions(
self,
admin_user: str,
jobs_with_shapes: List,
jobs_with_shapes: list,
filter_tasks,
api_version: Tuple[int],
api_version: tuple[int],
local_download: bool,
):
filter_ = "target_storage__location"
Expand Down
10 changes: 5 additions & 5 deletions tests/python/rest_api/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from copy import deepcopy
from http import HTTPStatus
from types import SimpleNamespace
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Optional

import pytest
from cvat_sdk import exceptions, models
Expand Down Expand Up @@ -60,7 +60,7 @@ def setup(self, _base_setup):
"""

@staticmethod
def _labels_by_source(labels: List[Dict], *, source_key: str) -> Dict[int, List[Dict]]:
def _labels_by_source(labels: list[dict], *, source_key: str) -> dict[int, list[dict]]:
labels_by_source = {}
for label in labels:
label_source = label.get(source_key)
Expand Down Expand Up @@ -216,7 +216,7 @@ def setup(self, restore_db_per_class, admin_user, labels, jobs_wlc, tasks_wlc, p
def _get_endpoint(self, api_client: ApiClient) -> Endpoint:
return api_client.labels_api.list_endpoint

def _get_field_samples(self, field: str) -> Tuple[Any, List[Dict[str, Any]]]:
def _get_field_samples(self, field: str) -> tuple[Any, list[dict[str, Any]]]:
if field == "parent":
parent_id, gt_objects = self._get_field_samples("parent_id")
parent_name = self._get_field(
Expand Down Expand Up @@ -584,8 +584,8 @@ def _test_update_denied(self, user, lid, data, expected_status=HTTPStatus.FORBID
return response

def _get_patch_data(
self, original_data: Dict[str, Any], **overrides
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
self, original_data: dict[str, Any], **overrides
) -> tuple[dict[str, Any], dict[str, Any]]:
result = deepcopy(original_data)
result.update(overrides)

Expand Down
4 changes: 2 additions & 2 deletions tests/python/rest_api/test_memberships.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: MIT

from http import HTTPStatus
from typing import ClassVar, List
from typing import ClassVar

import pytest
from cvat_sdk.api_client.api_client import ApiClient, Endpoint
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_can_use_simple_filter_for_object_list(self, field):
@pytest.mark.usefixtures("restore_db_per_function")
class TestPatchMemberships:
_ORG: ClassVar[int] = 1
ROLES: ClassVar[List[str]] = ["worker", "supervisor", "maintainer", "owner"]
ROLES: ClassVar[list[str]] = ["worker", "supervisor", "maintainer", "owner"]

def _test_can_change_membership(self, user, membership_id, new_role):
response = patch_method(
Expand Down
10 changes: 5 additions & 5 deletions tests/python/rest_api/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from itertools import product
from operator import itemgetter
from time import sleep
from typing import Dict, List, Optional, Tuple, Union
from typing import Optional, Union

import pytest
from cvat_sdk.api_client import ApiClient, Configuration, models
Expand Down Expand Up @@ -504,7 +504,7 @@ def _create_user(cls, api_client: ApiClient, email: str) -> str:
return json.loads(response.data)

@classmethod
def _create_org(cls, api_client: ApiClient, members: Optional[Dict[str, str]] = None) -> str:
def _create_org(cls, api_client: ApiClient, members: Optional[dict[str, str]] = None) -> str:
with api_client:
(_, response) = api_client.organizations_api.create(
models.OrganizationWriteRequest(slug="test_org_roles"), _parse_response=False
Expand Down Expand Up @@ -629,7 +629,7 @@ def _test_export_dataset(
username: str,
pid: int,
*,
api_version: Union[int, Tuple[int]],
api_version: Union[int, tuple[int]],
local_download: bool = True,
**kwargs,
) -> Optional[bytes]:
Expand Down Expand Up @@ -778,7 +778,7 @@ def test_can_import_export_dataset_with_some_format(self, format_name: str, api_
"local_download", (True, pytest.param(False, marks=pytest.mark.with_external_services))
)
def test_can_export_dataset_locally_and_to_cloud_with_both_api_versions(
self, admin_user: str, filter_projects, api_version: Tuple[int], local_download: bool
self, admin_user: str, filter_projects, api_version: tuple[int], local_download: bool
):
filter_ = "target_storage__location"
if local_download:
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def test_export_project_with_honeypots(

@pytest.mark.usefixtures("restore_db_per_function")
class TestPatchProjectLabel:
def _get_project_labels(self, pid, user, **kwargs) -> List[models.Label]:
def _get_project_labels(self, pid, user, **kwargs) -> list[models.Label]:
kwargs.setdefault("return_json", True)
with make_api_client(user) as api_client:
return get_paginated_collection(
Expand Down
Loading

0 comments on commit bff7d9a

Please sign in to comment.