Skip to content

Commit 073b880

Browse files
committed
delete old test
1 parent 90f76ee commit 073b880

File tree

17 files changed

+129
-82
lines changed

17 files changed

+129
-82
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
minversion = 3.7
33
log_cli=true
44
python_files = test_*.py
5-
addopts = -n auto --dist=loadscope
5+
;addopts = -n auto --dist=loadscope

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def search_annotation_classes(
580580
"""
581581
project_name, folder_name = extract_project_folder(project)
582582
classes = self.controller.search_annotation_classes(project_name, name_contains)
583-
return BaseSerializer.serialize_iterable(classes.data)
583+
return [i.dict(fill_enum_values=True) for i in classes.data]
584584

585585
def set_project_default_image_quality_in_editor(
586586
self,

src/superannotate/lib/app/serializers.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def _serialize(
4848
by_alias: bool = False,
4949
flat: bool = False,
5050
exclude: Set[str] = None,
51+
**kwargs
5152
):
5253
if not entity:
5354
return None
@@ -59,13 +60,15 @@ def _serialize(
5960
if len(fields) == 1:
6061
if flat:
6162
return entity.dict(
62-
include=fields, by_alias=by_alias, exclude=exclude
63+
include=fields, by_alias=by_alias, exclude=exclude, **kwargs
6364
)[next(iter(fields))]
6465
return entity.dict(
65-
include=fields, by_alias=by_alias, exclude=exclude
66+
include=fields, by_alias=by_alias, exclude=exclude, **kwargs
6667
)
67-
return entity.dict(include=fields, by_alias=by_alias, exclude=exclude)
68-
return entity.dict(by_alias=by_alias, exclude=exclude)
68+
return entity.dict(
69+
include=fields, by_alias=by_alias, exclude=exclude, **kwargs
70+
)
71+
return entity.dict(by_alias=by_alias, exclude=exclude, **kwargs)
6972
return entity.to_dict()
7073

7174
@classmethod
@@ -76,12 +79,13 @@ def serialize_iterable(
7679
by_alias: bool = False,
7780
flat: bool = False,
7881
exclude: Set = None,
82+
**kwargs
7983
) -> List[Any]:
8084
serialized_data = []
8185
for i in data:
8286
serialized_data.append(
8387
cls._fill_enum_values(
84-
cls._serialize(i, fields, by_alias, flat, exclude=exclude)
88+
cls._serialize(i, fields, by_alias, flat, exclude=exclude, **kwargs)
8589
)
8690
)
8791
return serialized_data
@@ -152,3 +156,19 @@ def serialize(
152156
if data["attribute"] == "ImageQuality":
153157
data["value"] = constance.ImageQuality.get_name(data["value"])
154158
return data
159+
160+
161+
class EntitySerializer:
162+
@classmethod
163+
def serialize(
164+
cls, data: Union[BaseModel, List[BaseModel]], **kwargs
165+
) -> Union[List[dict], dict]:
166+
if isinstance(data, (list, set)):
167+
for idx, item in enumerate(data):
168+
data[idx] = cls.serialize(item, **kwargs)
169+
for key, nested_model in data:
170+
if isinstance(nested_model, BaseModel) and getattr(
171+
nested_model, "fill_enum_values", False
172+
):
173+
setattr(data, key, cls.serialize(nested_model, **kwargs))
174+
return data.dict(**kwargs)

src/superannotate/lib/core/entities/classes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class AttributeGroup(BaseModel):
7575
is_multiselect: Optional[bool]
7676
attributes: Optional[List[Attribute]]
7777

78+
class Config:
79+
use_enum_values = True
80+
7881
def __hash__(self):
7982
return hash(f"{self.id}{self.class_id}{self.name}")
8083

@@ -93,3 +96,4 @@ def __hash__(self):
9396
class Config:
9497
validate_assignment = True
9598
exclude_none = True
99+
fill_enum_values = True

src/superannotate/lib/core/usecases/classes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
from typing import List
33

4+
from lib.core.conditions import Condition
45
from lib.core.entities import AnnotationClassEntity
56
from lib.core.entities import ProjectEntity
67
from lib.core.enums import ProjectType
@@ -10,6 +11,28 @@
1011
from lib.core.usecases.base import BaseReportableUseCase
1112

1213

14+
class GetAnnotationClassesUseCase(BaseReportableUseCase):
15+
def __init__(
16+
self,
17+
reporter: Reporter,
18+
project: ProjectEntity,
19+
backend_client: SuperannotateServiceProvider,
20+
condition: Condition = None,
21+
):
22+
super().__init__(reporter)
23+
self._project = project
24+
self._backend_client = backend_client
25+
self._condition = condition
26+
27+
def execute(self):
28+
self._response.data = self._backend_client.list_annotation_classes(
29+
project_id=self._project.id,
30+
team_id=self._project.team_id,
31+
query_string=self._condition.build_query() if self._condition else None,
32+
).data
33+
return self._response
34+
35+
1336
class CreateAnnotationClassUseCase(BaseReportableUseCase):
1437
def __init__(
1538
self,

src/superannotate/lib/core/usecases/images.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from lib.core.usecases.base import BaseInteractiveUseCase
4444
from lib.core.usecases.base import BaseReportableUseCase
4545
from lib.core.usecases.base import BaseUseCase
46-
from lib.core.usecases.projects import GetAnnotationClassesUseCase
46+
from lib.core.usecases.classes import GetAnnotationClassesUseCase
4747
from PIL import UnidentifiedImageError
4848
from superannotate.logger import get_default_logger
4949

@@ -738,14 +738,14 @@ def execute(self):
738738
return self._response
739739

740740

741-
class DownloadImageUseCase(BaseUseCase):
741+
class DownloadImageUseCase(BaseReportableUseCase):
742742
def __init__(
743743
self,
744+
reporter: Reporter,
744745
project: ProjectEntity,
745746
folder: FolderEntity,
746747
image: ImageEntity,
747748
images: BaseManageableRepository,
748-
classes: BaseManageableRepository,
749749
backend_service_provider: SuperannotateServiceProvider,
750750
annotation_classes: BaseReadOnlyRepository,
751751
download_path: str,
@@ -754,7 +754,7 @@ def __init__(
754754
include_fuse: bool = False,
755755
include_overlay: bool = False,
756756
):
757-
super().__init__()
757+
super().__init__(reporter)
758758
self._project = project
759759
self._image = image
760760
self._download_path = download_path
@@ -777,7 +777,9 @@ def __init__(
777777
annotation_classes=annotation_classes,
778778
)
779779
self.get_annotation_classes_ues_case = GetAnnotationClassesUseCase(
780-
classes=classes,
780+
reporter=self.reporter,
781+
project=self._project,
782+
backend_client=backend_service_provider
781783
)
782784

783785
def validate_project_type(self):

src/superannotate/lib/core/usecases/projects.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from lib.core.usecases.base import BaseReportableUseCase
2525
from lib.core.usecases.base import BaseUseCase
2626
from lib.core.usecases.base import BaseUserBasedUseCase
27+
from lib.core.usecases.classes import GetAnnotationClassesUseCase
2728
from requests.exceptions import RequestException
2829
from superannotate.logger import get_default_logger
2930

@@ -80,9 +81,10 @@ def execute(self):
8081
return self._response
8182

8283

83-
class GetProjectMetaDataUseCase(BaseUseCase):
84+
class GetProjectMetaDataUseCase(BaseReportableUseCase):
8485
def __init__(
8586
self,
87+
reporter: Reporter,
8688
project: ProjectEntity,
8789
service: SuperannotateServiceProvider,
8890
annotation_classes: BaseManageableRepository,
@@ -95,7 +97,7 @@ def __init__(
9597
include_contributors: bool,
9698
include_complete_image_count: bool,
9799
):
98-
super().__init__()
100+
super().__init__(reporter)
99101
self._project = project
100102
self._service = service
101103

@@ -112,7 +114,9 @@ def __init__(
112114

113115
@property
114116
def annotation_classes_use_case(self):
115-
return GetAnnotationClassesUseCase(classes=self._annotation_classes)
117+
return GetAnnotationClassesUseCase(
118+
reporter=self.reporter, project=self._project, backend_client=self._service
119+
)
116120

117121
@property
118122
def settings_use_case(self):
@@ -706,21 +710,6 @@ def execute(self):
706710
return self._response
707711

708712

709-
class GetAnnotationClassesUseCase(BaseUseCase):
710-
def __init__(
711-
self,
712-
classes: BaseManageableRepository,
713-
condition: Condition = None,
714-
):
715-
super().__init__()
716-
self._classes = classes
717-
self._condition = condition
718-
719-
def execute(self):
720-
self._response.data = self._classes.get_all(condition=self._condition)
721-
return self._response
722-
723-
724713
class UpdateSettingsUseCase(BaseUseCase):
725714
def __init__(
726715
self,

src/superannotate/lib/infrastructure/controller.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ def get_project_metadata(
732732
project = self._get_project(project_name)
733733

734734
use_case = usecases.GetProjectMetaDataUseCase(
735+
reporter=self.get_default_reporter(),
735736
project=project,
736737
service=self._backend_client,
737738
annotation_classes=AnnotationClassRepository(
@@ -773,16 +774,16 @@ def get_project_workflow(self, project_name: str):
773774
return use_case.execute()
774775

775776
def search_annotation_classes(self, project_name: str, name_contains: str = None):
776-
project_entity = self._get_project(project_name)
777+
project = self._get_project(project_name)
777778
condition = None
778779
if name_contains:
779780
condition = Condition("name", name_contains, EQ) & Condition(
780781
"pattern", True, EQ
781782
)
782783
use_case = usecases.GetAnnotationClassesUseCase(
783-
classes=AnnotationClassRepository(
784-
service=self._backend_client, project=project_entity
785-
),
784+
reporter=self.get_default_reporter(),
785+
project=project,
786+
backend_client=self.backend_client,
786787
condition=condition,
787788
)
788789
return use_case.execute()
@@ -993,11 +994,11 @@ def download_image(
993994
image = self._get_image(project, image_name, folder)
994995

995996
use_case = usecases.DownloadImageUseCase(
997+
reporter=self.get_default_reporter(),
996998
project=project,
997999
folder=folder,
9981000
image=image,
9991001
images=self.images,
1000-
classes=AnnotationClassRepository(self._backend_client, project),
10011002
backend_service_provider=self._backend_client,
10021003
download_path=download_path,
10031004
image_variant=image_variant,

src/superannotate/lib/infrastructure/stream_data_handler.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,22 @@ async def get_data(
5757
data: list,
5858
method: str = "post",
5959
params=None,
60-
chunk_size: int = 1000,
60+
chunk_size: int = 5000,
6161
verify_ssl: bool = False,
6262
):
6363
async with aiohttp.ClientSession(
6464
headers=self._headers,
6565
connector=aiohttp.TCPConnector(ssl=verify_ssl),
6666
) as session:
67-
if chunk_size:
68-
for i in range(0, len(data), chunk_size):
69-
data_to_process = data[i : i + chunk_size]
70-
async for annotation in self.fetch(
71-
method,
72-
session,
73-
url,
74-
self._process_data(data_to_process),
75-
params=params,
76-
):
77-
self._annotations.append(
78-
self._callback(annotation) if self._callback else annotation
79-
)
80-
else:
67+
for i in range(0, len(data), chunk_size):
68+
data_to_process = data[i : i + chunk_size] # noqa
69+
params["limit"] = len(data_to_process)
8170
async for annotation in self.fetch(
82-
method, session, url, self._process_data(data), params=params
71+
method,
72+
session,
73+
url,
74+
self._process_data(data_to_process),
75+
params=params,
8376
):
8477
self._annotations.append(
8578
self._callback(annotation) if self._callback else annotation
@@ -115,7 +108,8 @@ async def download_data(
115108
items_downloaded: int = 0
116109
if chunk_size and data:
117110
for i in range(0, len(data), chunk_size):
118-
data_to_process = data[i : i + chunk_size]
111+
data_to_process = data[i : i + chunk_size] # noqa
112+
params["limit"] = len(data_to_process)
119113
async for annotation in self.fetch(
120114
method,
121115
session,

tests/integration/aggregations/test_df_processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import os
2-
from os.path import dirname
32
from pathlib import Path
43

54
import pytest
65

76
from src.superannotate import SAClient
8-
sa = SAClient()
97
from tests.integration.base import BaseTestCase
108

9+
sa = SAClient()
10+
1111

1212
class TestDF(BaseTestCase):
1313
PROJECT_NAME = "test df processing"

0 commit comments

Comments
 (0)