|
| 1 | +import tempfile |
| 2 | +from pathlib import Path |
| 3 | +import os |
| 4 | +import shutil |
| 5 | +from os.path import join |
| 6 | +import json |
| 7 | +import pytest |
| 8 | +from unittest.mock import patch |
| 9 | +from unittest.mock import MagicMock |
| 10 | + |
| 11 | +import src.superannotate as sa |
| 12 | +from tests.integration.base import BaseTestCase |
| 13 | + |
| 14 | + |
| 15 | +class TestAnnotationUploadVectorWithoutClasses(BaseTestCase): |
| 16 | + PROJECT_NAME = "TestAnnotationUploadVectorWithoutClasses" |
| 17 | + PROJECT_DESCRIPTION = "Desc" |
| 18 | + PROJECT_TYPE = "Vector" |
| 19 | + S3_FOLDER_PATH = "sample_project_pixel" |
| 20 | + TEST_FOLDER_PATH = "data_set/sample_project_vector" |
| 21 | + IMAGE_NAME = "example_image_1.jpg" |
| 22 | + |
| 23 | + @property |
| 24 | + def folder_path(self): |
| 25 | + return os.path.join(Path(__file__).parent.parent.parent, self.TEST_FOLDER_PATH) |
| 26 | + |
| 27 | + @pytest.mark.flaky(reruns=3) |
| 28 | + @patch("lib.infrastructure.controller.Reporter", MagicMock()) |
| 29 | + def test_annotation_upload(self): |
| 30 | + annotation_path = join(self.folder_path, f"{self.IMAGE_NAME}___objects.json") |
| 31 | + sa.upload_image_to_project(self.PROJECT_NAME, join(self.folder_path, self.IMAGE_NAME)) |
| 32 | + dir_name = "tmp" |
| 33 | + with tempfile.TemporaryDirectory() as tmp_dir: |
| 34 | + shutil.copytree(self.folder_path, f"{tmp_dir}/{dir_name}") |
| 35 | + shutil.rmtree(f"{tmp_dir}/{dir_name}/classes") |
| 36 | + sa.upload_image_annotations(self.PROJECT_NAME, self.IMAGE_NAME, annotation_path) |
| 37 | + with tempfile.TemporaryDirectory() as classes_dir: |
| 38 | + classes_path = sa.download_annotation_classes_json(self.PROJECT_NAME, classes_dir) |
| 39 | + self.assertEqual(json.load(open(classes_path, "r")), []) |
0 commit comments