Skip to content

Commit e03f4a6

Browse files
authored
Merge pull request #184 from superannotateai/fix_test
Fix test
2 parents 89b671f + eea979c commit e03f4a6

File tree

2 files changed

+99
-92
lines changed

2 files changed

+99
-92
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+
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+
)
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=temp_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)

tests/integration/test_benchmark.py

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,64 +43,67 @@ def test_benchmark(self):
4343
"folderName",
4444
"score",
4545
]
46-
export_path = self.export_path
47-
for i in range(1, 4):
48-
sa.create_folder(self.PROJECT_NAME, self.CONSENSUS_PREFIX + str(i))
49-
sa.create_annotation_classes_from_classes_json(
50-
self.PROJECT_NAME, self.export_path + "/classes/classes.json"
51-
)
52-
sa.upload_images_from_folder_to_project(
53-
self.PROJECT_NAME,
54-
self.export_path + "/images",
55-
annotation_status="Completed",
56-
)
57-
for i in range(1, 4):
46+
47+
with tempfile.TemporaryDirectory() as tmpdir:
48+
temp_export_path = str(tmpdir)
49+
50+
for i in range(1, 4):
51+
sa.create_folder(self.PROJECT_NAME, self.CONSENSUS_PREFIX + str(i))
52+
sa.create_annotation_classes_from_classes_json(
53+
self.PROJECT_NAME, self.export_path + "/classes/classes.json"
54+
)
5855
sa.upload_images_from_folder_to_project(
59-
self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i),
56+
self.PROJECT_NAME,
6057
self.export_path + "/images",
6158
annotation_status="Completed",
6259
)
63-
time.sleep(2)
64-
sa.upload_annotations_from_folder_to_project(
65-
self.PROJECT_NAME, self.export_path
66-
)
67-
for i in range(1, 4):
60+
for i in range(1, 4):
61+
sa.upload_images_from_folder_to_project(
62+
self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i),
63+
self.export_path + "/images",
64+
annotation_status="Completed",
65+
)
66+
time.sleep(2)
6867
sa.upload_annotations_from_folder_to_project(
69-
self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i),
70-
self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i),
68+
self.PROJECT_NAME, self.export_path
7169
)
70+
for i in range(1, 4):
71+
sa.upload_annotations_from_folder_to_project(
72+
self.PROJECT_NAME + f"/{self.CONSENSUS_PREFIX}" + str(i),
73+
self.export_path + f"/{self.CONSENSUS_PREFIX}" + str(i),
74+
)
7275

73-
for annotation_type in annotation_types:
74-
res_df = sa.benchmark(
75-
self.PROJECT_NAME,
76-
self.GT_FOLDER_NAME,
77-
folder_names,
78-
annot_type=annotation_type,
79-
)
80-
# test content of projectName column
81-
assert sorted(res_df["folderName"].unique()) == folder_names
76+
for annotation_type in annotation_types:
77+
res_df = sa.benchmark(
78+
self.PROJECT_NAME,
79+
self.GT_FOLDER_NAME,
80+
folder_names,
81+
annot_type=annotation_type,
82+
)
83+
# test content of projectName column
84+
assert sorted(res_df["folderName"].unique()) == folder_names
8285

83-
# test structure of resulting DataFrame
84-
assert sorted(res_df.columns) == sorted(df_column_names)
86+
# test structure of resulting DataFrame
87+
assert sorted(res_df.columns) == sorted(df_column_names)
8588

86-
# test lower bound of the score
87-
assert (res_df["score"] >= 0).all()
89+
# test lower bound of the score
90+
assert (res_df["score"] >= 0).all()
8891

89-
# test upper bound of the score
90-
assert (res_df["score"] <= 1).all()
92+
# test upper bound of the score
93+
assert (res_df["score"] <= 1).all()
9194

92-
image_names = [
93-
"bonn_000000_000019_leftImg8bit.png",
94-
"bielefeld_000000_000321_leftImg8bit.png",
95-
]
95+
image_names = [
96+
"bonn_000000_000019_leftImg8bit.png",
97+
"bielefeld_000000_000321_leftImg8bit.png",
98+
]
9699

97-
# test filtering images with given image names list
98-
res_images = sa.benchmark(
99-
self.PROJECT_NAME,
100-
self.GT_FOLDER_NAME,
101-
folder_names,
102-
export_root=export_path,
103-
image_list=image_names,
104-
)
100+
# test filtering images with given image names list
101+
res_images = sa.benchmark(
102+
self.PROJECT_NAME,
103+
self.GT_FOLDER_NAME,
104+
folder_names,
105+
export_root=temp_export_path,
106+
image_list=image_names,
107+
)
105108

106-
assert sorted(res_images["imageName"].unique()) == sorted(image_names)
109+
assert sorted(res_images["imageName"].unique()) == sorted(image_names)

0 commit comments

Comments
 (0)