|
1 | 1 | import os |
| 2 | +import tempfile |
2 | 3 | import time |
3 | 4 | from os.path import dirname |
4 | 5 |
|
@@ -38,60 +39,63 @@ def test_consensus(self): |
38 | 39 | "folderName", |
39 | 40 | "score", |
40 | 41 | ] |
41 | | - export_path = self.export_path |
42 | | - for i in range(1, 4): |
43 | | - sa.create_folder(self.PROJECT_NAME, "consensus_" + str(i)) |
44 | | - sa.create_annotation_classes_from_classes_json( |
45 | | - self.PROJECT_NAME, self.export_path + "/classes/classes.json" |
46 | | - ) |
47 | | - sa.upload_images_from_folder_to_project( |
48 | | - self.PROJECT_NAME, |
49 | | - self.export_path + "/images", |
50 | | - annotation_status="Completed", |
51 | | - ) |
52 | | - for i in range(1, 4): |
| 42 | + |
| 43 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 44 | + temp_export_path = str(tmpdir) |
| 45 | + |
| 46 | + for i in range(1, 4): |
| 47 | + sa.create_folder(self.PROJECT_NAME, "consensus_" + str(i)) |
| 48 | + sa.create_annotation_classes_from_classes_json( |
| 49 | + self.PROJECT_NAME, self.export_path + "/classes/classes.json" |
| 50 | + ) |
53 | 51 | sa.upload_images_from_folder_to_project( |
54 | | - self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), |
| 52 | + self.PROJECT_NAME, |
55 | 53 | self.export_path + "/images", |
56 | 54 | annotation_status="Completed", |
57 | 55 | ) |
58 | | - time.sleep(2) |
59 | | - sa.upload_annotations_from_folder_to_project( |
60 | | - self.PROJECT_NAME, self.export_path |
61 | | - ) |
62 | | - for i in range(1, 4): |
| 56 | + for i in range(1, 4): |
| 57 | + sa.upload_images_from_folder_to_project( |
| 58 | + self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), |
| 59 | + self.export_path + "/images", |
| 60 | + annotation_status="Completed", |
| 61 | + ) |
| 62 | + time.sleep(2) |
63 | 63 | sa.upload_annotations_from_folder_to_project( |
64 | | - self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), |
65 | | - self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i), |
| 64 | + self.PROJECT_NAME, self.export_path |
66 | 65 | ) |
| 66 | + for i in range(1, 4): |
| 67 | + sa.upload_annotations_from_folder_to_project( |
| 68 | + self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i), |
| 69 | + self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i), |
| 70 | + ) |
67 | 71 |
|
68 | | - for annot_type in annot_types: |
69 | | - res_df = sa.consensus( |
70 | | - self.PROJECT_NAME, folder_names, annot_type=annot_type |
71 | | - ) |
72 | | - # test content of projectName column |
73 | | - assert sorted(res_df["folderName"].unique()) == folder_names |
| 72 | + for annot_type in annot_types: |
| 73 | + res_df = sa.consensus( |
| 74 | + self.PROJECT_NAME, folder_names, annot_type=annot_type |
| 75 | + ) |
| 76 | + # test content of projectName column |
| 77 | + assert sorted(res_df["folderName"].unique()) == folder_names |
74 | 78 |
|
75 | | - # test structure of resulting DataFrame |
76 | | - assert sorted(res_df.columns) == sorted(df_column_names) |
| 79 | + # test structure of resulting DataFrame |
| 80 | + assert sorted(res_df.columns) == sorted(df_column_names) |
77 | 81 |
|
78 | | - # test lower bound of the score |
79 | | - assert (res_df["score"] >= 0).all() |
| 82 | + # test lower bound of the score |
| 83 | + assert (res_df["score"] >= 0).all() |
80 | 84 |
|
81 | | - # test upper bound of the score |
82 | | - assert (res_df["score"] <= 1).all() |
| 85 | + # test upper bound of the score |
| 86 | + assert (res_df["score"] <= 1).all() |
83 | 87 |
|
84 | | - image_names = [ |
85 | | - "bonn_000000_000019_leftImg8bit.png", |
86 | | - "bielefeld_000000_000321_leftImg8bit.png", |
87 | | - ] |
| 88 | + image_names = [ |
| 89 | + "bonn_000000_000019_leftImg8bit.png", |
| 90 | + "bielefeld_000000_000321_leftImg8bit.png", |
| 91 | + ] |
88 | 92 |
|
89 | | - # test filtering images with given image names list |
90 | | - res_images = sa.consensus( |
91 | | - self.PROJECT_NAME, |
92 | | - folder_names, |
93 | | - export_root=export_path, |
94 | | - image_list=image_names, |
95 | | - ) |
| 93 | + # test filtering images with given image names list |
| 94 | + res_images = sa.consensus( |
| 95 | + self.PROJECT_NAME, |
| 96 | + folder_names, |
| 97 | + export_root=temp_export_path, |
| 98 | + image_list=image_names, |
| 99 | + ) |
96 | 100 |
|
97 | | - assert sorted(res_images["imageName"].unique()) == sorted(image_names) |
| 101 | + assert sorted(res_images["imageName"].unique()) == sorted(image_names) |
0 commit comments