From bba6ac9bc5809da3dc80e120f0082bb68304d789 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sun, 6 Nov 2022 13:41:22 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- .../cropped_annotations_service.py | 3 +-- ebl/fragmentarium/domain/annotation.py | 20 +++++++++---------- ebl/tests/test_mongo_collection.py | 11 +++++----- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/ebl/fragmentarium/application/cropped_annotations_service.py b/ebl/fragmentarium/application/cropped_annotations_service.py index 22b0a9f44..836b18689 100644 --- a/ebl/fragmentarium/application/cropped_annotations_service.py +++ b/ebl/fragmentarium/application/cropped_annotations_service.py @@ -21,8 +21,7 @@ def find_annotations_by_sign(self, sign: str) -> Sequence[CroppedAnnotation]: cropped_image_annotations = [] for annotation in annotations: for annotation_elem in annotation.annotations: - cropped_sign = annotation_elem.cropped_sign - if cropped_sign: + if cropped_sign := annotation_elem.cropped_sign: cropped_sign_image = ( self._cropped_sign_image_repository.query_by_id( cropped_sign.image_id diff --git a/ebl/fragmentarium/domain/annotation.py b/ebl/fragmentarium/domain/annotation.py index 79ec6fb73..e89994b68 100644 --- a/ebl/fragmentarium/domain/annotation.py +++ b/ebl/fragmentarium/domain/annotation.py @@ -96,17 +96,15 @@ def from_annotations( image_width: int, image_height: int, annotations: Sequence[Annotation] ) -> Sequence["BoundingBox"]: return tuple( - [ - BoundingBox.from_relative_coordinates( - annotation.geometry.x, - annotation.geometry.y, - annotation.geometry.width, - annotation.geometry.height, - image_width, - image_height, - ) - for annotation in annotations - ] + BoundingBox.from_relative_coordinates( + annotation.geometry.x, + annotation.geometry.y, + annotation.geometry.width, + annotation.geometry.height, + image_width, + image_height, + ) + for annotation in annotations ) diff --git a/ebl/tests/test_mongo_collection.py b/ebl/tests/test_mongo_collection.py index 0c3c82fa5..81f010315 100644 --- a/ebl/tests/test_mongo_collection.py +++ b/ebl/tests/test_mongo_collection.py @@ -58,14 +58,14 @@ def test_find_many(collection): collection.insert_one(document_match2) collection.insert_one(document_no_match) - assert [document for document in collection.find_many({"data": "payload"})] == [ + assert list(collection.find_many({"data": "payload"})) == [ document_match1, document_match2, ] def test_find_many_document_not_found(collection): - assert list(collection.find_many({})) == [] + assert not list(collection.find_many({})) def test_aggregate(collection): @@ -76,9 +76,10 @@ def test_aggregate(collection): collection.insert_one(document_match2) collection.insert_one(document_no_match) - assert [ - document for document in collection.aggregate([{"$match": {"data": "payload"}}]) - ] == [document_match1, document_match2] + assert list(collection.aggregate([{"$match": {"data": "payload"}}])) == [ + document_match1, + document_match2, + ] def test_update(collection):