Skip to content

Commit 464a5ce

Browse files
committed
Fix test
1 parent 15aa09d commit 464a5ce

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

tests/convertors/test_consensus.py

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import tempfile
23
import time
34
from os.path import dirname
45

@@ -38,60 +39,63 @@ def test_consensus(self):
3839
"folderName",
3940
"score",
4041
]
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+
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+
)
5351
sa.upload_images_from_folder_to_project(
54-
self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i),
52+
self.PROJECT_NAME,
5553
self.export_path + "/images",
5654
annotation_status="Completed",
5755
)
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)
6363
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
6665
)
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+
)
6771

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
7478

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)
7781

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()
8084

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()
8387

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+
]
8892

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=export_path,
98+
image_list=image_names,
99+
)
96100

97-
assert sorted(res_images["imageName"].unique()) == sorted(image_names)
101+
assert sorted(res_images["imageName"].unique()) == sorted(image_names)

0 commit comments

Comments
 (0)