From 464a5ce737c2df066cfd54ed8b256109b2a52192 Mon Sep 17 00:00:00 2001 From: shab Date: Thu, 2 Sep 2021 15:23:32 +0400 Subject: [PATCH 1/3] Fix test --- tests/convertors/test_consensus.py | 92 ++++++++++++++++-------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/tests/convertors/test_consensus.py b/tests/convertors/test_consensus.py index a99bd6813..2c948f7d4 100644 --- a/tests/convertors/test_consensus.py +++ b/tests/convertors/test_consensus.py @@ -1,4 +1,5 @@ import os +import tempfile import time from os.path import dirname @@ -38,60 +39,63 @@ def test_consensus(self): "folderName", "score", ] - export_path = self.export_path - for i in range(1, 4): - sa.create_folder(self.PROJECT_NAME, "consensus_" + str(i)) - sa.create_annotation_classes_from_classes_json( - self.PROJECT_NAME, self.export_path + "/classes/classes.json" - ) - sa.upload_images_from_folder_to_project( - self.PROJECT_NAME, - self.export_path + "/images", - annotation_status="Completed", - ) - for i in range(1, 4): + + with tempfile.TemporaryDirectory() as tmpdir: + export_path = str(tmpdir) + + for i in range(1, 4): + sa.create_folder(self.PROJECT_NAME, "consensus_" + str(i)) + sa.create_annotation_classes_from_classes_json( + self.PROJECT_NAME, self.export_path + "/classes/classes.json" + ) sa.upload_images_from_folder_to_project( - self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.PROJECT_NAME, self.export_path + "/images", annotation_status="Completed", ) - time.sleep(2) - sa.upload_annotations_from_folder_to_project( - self.PROJECT_NAME, self.export_path - ) - for i in range(1, 4): + for i in range(1, 4): + sa.upload_images_from_folder_to_project( + self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.export_path + "/images", + annotation_status="Completed", + ) + time.sleep(2) sa.upload_annotations_from_folder_to_project( - self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), - self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.PROJECT_NAME, self.export_path ) + for i in range(1, 4): + sa.upload_annotations_from_folder_to_project( + self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i), + ) - for annot_type in annot_types: - res_df = sa.consensus( - self.PROJECT_NAME, folder_names, annot_type=annot_type - ) - # test content of projectName column - assert sorted(res_df["folderName"].unique()) == folder_names + for annot_type in annot_types: + res_df = sa.consensus( + self.PROJECT_NAME, folder_names, annot_type=annot_type + ) + # test content of projectName column + assert sorted(res_df["folderName"].unique()) == folder_names - # test structure of resulting DataFrame - assert sorted(res_df.columns) == sorted(df_column_names) + # test structure of resulting DataFrame + assert sorted(res_df.columns) == sorted(df_column_names) - # test lower bound of the score - assert (res_df["score"] >= 0).all() + # test lower bound of the score + assert (res_df["score"] >= 0).all() - # test upper bound of the score - assert (res_df["score"] <= 1).all() + # test upper bound of the score + assert (res_df["score"] <= 1).all() - image_names = [ - "bonn_000000_000019_leftImg8bit.png", - "bielefeld_000000_000321_leftImg8bit.png", - ] + image_names = [ + "bonn_000000_000019_leftImg8bit.png", + "bielefeld_000000_000321_leftImg8bit.png", + ] - # test filtering images with given image names list - res_images = sa.consensus( - self.PROJECT_NAME, - folder_names, - export_root=export_path, - image_list=image_names, - ) + # test filtering images with given image names list + res_images = sa.consensus( + self.PROJECT_NAME, + folder_names, + export_root=export_path, + image_list=image_names, + ) - assert sorted(res_images["imageName"].unique()) == sorted(image_names) + assert sorted(res_images["imageName"].unique()) == sorted(image_names) From 42cd824c804d504df64b208d2197d93dc9b3ccf8 Mon Sep 17 00:00:00 2001 From: shab Date: Thu, 2 Sep 2021 16:03:12 +0400 Subject: [PATCH 2/3] add fix ignore --- tests/convertors/test_consensus.py | 4 +- tests/integration/test_benchmark.py | 99 +++++++++++++++-------------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/tests/convertors/test_consensus.py b/tests/convertors/test_consensus.py index 2c948f7d4..4418bcbf4 100644 --- a/tests/convertors/test_consensus.py +++ b/tests/convertors/test_consensus.py @@ -41,7 +41,7 @@ def test_consensus(self): ] with tempfile.TemporaryDirectory() as tmpdir: - export_path = str(tmpdir) + temp_export_path = str(tmpdir) for i in range(1, 4): sa.create_folder(self.PROJECT_NAME, "consensus_" + str(i)) @@ -94,7 +94,7 @@ def test_consensus(self): res_images = sa.consensus( self.PROJECT_NAME, folder_names, - export_root=export_path, + export_root=temp_export_path, image_list=image_names, ) diff --git a/tests/integration/test_benchmark.py b/tests/integration/test_benchmark.py index d1f79fede..1865932d5 100644 --- a/tests/integration/test_benchmark.py +++ b/tests/integration/test_benchmark.py @@ -43,64 +43,67 @@ def test_benchmark(self): "folderName", "score", ] - export_path = self.export_path - for i in range(1, 4): - sa.create_folder(self.PROJECT_NAME, self.CONSENSUS_PREFIX + str(i)) - sa.create_annotation_classes_from_classes_json( - self.PROJECT_NAME, self.export_path + "/classes/classes.json" - ) - sa.upload_images_from_folder_to_project( - self.PROJECT_NAME, - self.export_path + "/images", - annotation_status="Completed", - ) - for i in range(1, 4): + + with tempfile.TemporaryDirectory() as tmpdir: + temp_export_path = str(tmpdir) + + for i in range(1, 4): + sa.create_folder(self.PROJECT_NAME, self.CONSENSUS_PREFIX + str(i)) + sa.create_annotation_classes_from_classes_json( + self.PROJECT_NAME, self.export_path + "/classes/classes.json" + ) sa.upload_images_from_folder_to_project( - self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.PROJECT_NAME, self.export_path + "/images", annotation_status="Completed", ) - time.sleep(2) - sa.upload_annotations_from_folder_to_project( - self.PROJECT_NAME, self.export_path - ) - for i in range(1, 4): + for i in range(1, 4): + sa.upload_images_from_folder_to_project( + self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.export_path + "/images", + annotation_status="Completed", + ) + time.sleep(2) sa.upload_annotations_from_folder_to_project( - self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), - self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.PROJECT_NAME, self.export_path ) + for i in range(1, 4): + sa.upload_annotations_from_folder_to_project( + self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), + self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i), + ) - for annotation_type in annotation_types: - res_df = sa.benchmark( - self.PROJECT_NAME, - self.GT_FOLDER_NAME, - folder_names, - annot_type=annotation_type, - ) - # test content of projectName column - assert sorted(res_df["folderName"].unique()) == folder_names + for annotation_type in annotation_types: + res_df = sa.benchmark( + self.PROJECT_NAME, + self.GT_FOLDER_NAME, + folder_names, + annot_type=annotation_type, + ) + # test content of projectName column + assert sorted(res_df["folderName"].unique()) == folder_names - # test structure of resulting DataFrame - assert sorted(res_df.columns) == sorted(df_column_names) + # test structure of resulting DataFrame + assert sorted(res_df.columns) == sorted(df_column_names) - # test lower bound of the score - assert (res_df["score"] >= 0).all() + # test lower bound of the score + assert (res_df["score"] >= 0).all() - # test upper bound of the score - assert (res_df["score"] <= 1).all() + # test upper bound of the score + assert (res_df["score"] <= 1).all() - image_names = [ - "bonn_000000_000019_leftImg8bit.png", - "bielefeld_000000_000321_leftImg8bit.png", - ] + image_names = [ + "bonn_000000_000019_leftImg8bit.png", + "bielefeld_000000_000321_leftImg8bit.png", + ] - # test filtering images with given image names list - res_images = sa.benchmark( - self.PROJECT_NAME, - self.GT_FOLDER_NAME, - folder_names, - export_root=export_path, - image_list=image_names, - ) + # test filtering images with given image names list + res_images = sa.benchmark( + self.PROJECT_NAME, + self.GT_FOLDER_NAME, + folder_names, + export_root=temp_export_path, + image_list=image_names, + ) - assert sorted(res_images["imageName"].unique()) == sorted(image_names) + assert sorted(res_images["imageName"].unique()) == sorted(image_names) From eea979cd6b0cf2c000c3704598f4897c32d0f2de Mon Sep 17 00:00:00 2001 From: shab Date: Thu, 2 Sep 2021 16:05:33 +0400 Subject: [PATCH 3/3] fix test --- src/superannotate/lib/infrastructure/controller.py | 2 +- src/superannotate/lib/infrastructure/services.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/superannotate/lib/infrastructure/controller.py b/src/superannotate/lib/infrastructure/controller.py index 06844900e..917de0831 100644 --- a/src/superannotate/lib/infrastructure/controller.py +++ b/src/superannotate/lib/infrastructure/controller.py @@ -726,7 +726,7 @@ def search_annotation_classes(self, project_name: str, name_prefix: str = None): classes=AnnotationClassRepository( service=self._backend_client, project=project_entity ), - condition=condition + condition=condition, ) return use_case.execute() diff --git a/src/superannotate/lib/infrastructure/services.py b/src/superannotate/lib/infrastructure/services.py index 8b25e4862..2aa348dd9 100644 --- a/src/superannotate/lib/infrastructure/services.py +++ b/src/superannotate/lib/infrastructure/services.py @@ -1,4 +1,3 @@ -import os from contextlib import contextmanager from datetime import datetime from typing import Dict @@ -27,7 +26,9 @@ class BaseBackendService(SuerannotateServiceProvider): Base service class """ - def __init__(self, api_url: str, auth_token: str, logger, paginate_by=None, verify_ssl=True): + def __init__( + self, api_url: str, auth_token: str, logger, paginate_by=None, verify_ssl=True + ): self.api_url = api_url self._auth_token = auth_token self.logger = logger