Skip to content

Commit e08b760

Browse files
committed
increase coverage
1 parent 7f2f554 commit e08b760

File tree

14 files changed

+87
-144
lines changed

14 files changed

+87
-144
lines changed

superannotate/input_converters/conversion.py

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -78,63 +78,73 @@
7878

7979
def _passes_sanity_checks(args):
8080
if not isinstance(args.input_dir, (str, Path)):
81-
log_msg = "'input_dir' should be 'str' or 'Path' type, not '%s'" % (
82-
type(args.input_dir)
81+
raise SABaseException(
82+
0, "'input_dir' should be 'str' or 'Path' type, not '%s'" %
83+
(type(args.input_dir))
8384
)
84-
raise SABaseException(0, log_msg)
8585

8686
if not isinstance(args.output_dir, (str, Path)):
87-
log_msg = "'output_dir' should be 'str' or 'Path' type, not {}".format(
88-
type(args.output_dir)
87+
raise SABaseException(
88+
0, "'output_dir' should be 'str' or 'Path' type, not {}".format(
89+
type(args.output_dir)
90+
)
8991
)
90-
raise SABaseException(0, log_msg)
9192

9293
if args.dataset_format not in ALLOWED_ANNOTATION_IMPORT_FORMATS.keys():
93-
log_msg = "'%s' converter doesn't exist. Possible candidates are '%s'"\
94-
% (args.dataset_format, ALLOWED_ANNOTATION_IMPORT_FORMATS.keys())
95-
raise SABaseException(0, log_msg)
94+
raise SABaseException(
95+
0, "'%s' converter doesn't exist. Possible candidates are '%s'" %
96+
(args.dataset_format, ALLOWED_ANNOTATION_IMPORT_FORMATS.keys())
97+
)
9698

9799
if not isinstance(args.dataset_name, str):
98-
log_msg = "'dataset_name' should be 'str' type, not {}".format(
99-
type(args.dataset_name)
100+
raise SABaseException(
101+
0, "'dataset_name' should be 'str' type, not {}".format(
102+
type(args.dataset_name)
103+
)
100104
)
101-
raise SABaseException(0, log_msg)
102105

103106
if args.project_type not in ALLOWED_PROJECT_TYPES:
104-
log_msg = "Please enter valid project type: 'Pixel' or 'Vector'"
105-
raise SABaseException(0, log_msg)
107+
raise SABaseException(
108+
0, "Please enter valid project type: 'Pixel' or 'Vector'"
109+
)
106110

107111
if args.task not in ALLOWED_TASK_TYPES:
108-
log_msg = "Please enter valid task '%s'" % (ALLOWED_TASK_TYPES)
109-
raise SABaseException(0, log_msg)
112+
raise SABaseException(
113+
0, "Please enter valid task '%s'" % (ALLOWED_TASK_TYPES)
114+
)
110115

111116
if 'platform' in args:
112117
if args.platform not in AVAILABLE_PLATFORMS:
113-
log_msg = "Please enter valid platform: 'Desktop' or 'Web'"
114-
raise SABaseException(0, log_msg)
118+
raise SABaseException(
119+
0, "Please enter valid platform: 'Desktop' or 'Web'"
120+
)
115121

116122
if args.task == "Pixel" and args.platform == "Desktop":
117-
log_msg = "Sorry, but Desktop Application doesn't support 'Pixel' projects yet."
118-
raise SABaseException(0, log_msg)
123+
raise SABaseException(
124+
0,
125+
"Sorry, but Desktop Application doesn't support 'Pixel' projects."
126+
)
119127

120-
return True
128+
# return True
121129

122130

123131
def _passes_converter_sanity(args, direction):
124132
converter_values = (args.project_type, args.task)
133+
test_passed = False
125134
if direction == 'import':
126135
if converter_values in ALLOWED_ANNOTATION_IMPORT_FORMATS[
127136
args.dataset_format]:
128-
return True
137+
test_passed = True
129138
else:
130139
if converter_values in ALLOWED_ANNOTATION_EXPORT_FORMATS[
131140
args.dataset_format]:
132-
return True
141+
test_passed = True
133142

134-
log_msg = "Please enter valid converter values. You can check available \
135-
candidates in the documentation(https://superannotate.readthedocs.io/en/latest/index.html)."
136-
137-
raise SABaseException(log_msg)
143+
if not test_passed:
144+
raise SABaseException(
145+
0,
146+
"Please enter valid converter values. You can check available candidates in the documentation(https://superannotate.readthedocs.io/en/latest/index.html)."
147+
)
138148

139149

140150
def export_annotation_format(
@@ -195,10 +205,8 @@ def export_annotation_format(
195205
platform=platform,
196206
)
197207

198-
if not _passes_sanity_checks(args):
199-
sys.exit()
200-
if not _passes_converter_sanity(args, 'export'):
201-
sys.exit()
208+
_passes_sanity_checks(args)
209+
_passes_converter_sanity(args, 'export')
202210

203211
export_from_sa(args)
204212

@@ -343,10 +351,8 @@ def import_annotation_format(
343351
platform=platform,
344352
)
345353

346-
if not _passes_sanity_checks(args):
347-
sys.exit()
348-
if not _passes_converter_sanity(args, 'import'):
349-
sys.exit()
354+
_passes_sanity_checks(args)
355+
_passes_converter_sanity(args, 'import')
350356

351357
import_to_sa(args)
352358

@@ -363,20 +369,21 @@ def convert_platform(input_dir, output_dir, input_platform):
363369
364370
"""
365371
if not isinstance(input_dir, (str, Path)):
366-
log_msg = "'input_dir' should be 'str' or 'Path' type, not '%s'" % (
367-
type(input_dir)
372+
raise SABaseException(
373+
0, "'input_dir' should be 'str' or 'Path' type, not '%s'" %
374+
(type(input_dir))
368375
)
369-
raise SABaseException(0, log_msg)
370376

371377
if not isinstance(output_dir, (str, Path)):
372-
log_msg = "'output_dir' should be 'str' or 'Path' type, not '%s'" % (
373-
type(output_dir)
378+
raise SABaseException(
379+
0, "'output_dir' should be 'str' or 'Path' type, not '%s'" %
380+
(type(output_dir))
374381
)
375-
raise SABaseException(0, log_msg)
376382

377383
if input_platform not in AVAILABLE_PLATFORMS:
378-
log_msg = "Please enter valid platform: 'Desktop' or 'Web'"
379-
raise SABaseException(0, log_msg)
384+
raise SABaseException(
385+
0, "Please enter valid platform: 'Desktop' or 'Web'"
386+
)
380387

381388
sa_convert_platform(input_dir, output_dir, input_platform)
382389

@@ -392,15 +399,15 @@ def convert_project_type(input_dir, output_dir):
392399
"""
393400

394401
if not isinstance(input_dir, (str, Path)):
395-
log_msg = "'input_dir' should be 'str' or 'Path' type, not '%s'" % (
396-
type(input_dir)
402+
raise SABaseException(
403+
0, "'input_dir' should be 'str' or 'Path' type, not '%s'" %
404+
(type(input_dir))
397405
)
398-
raise SABaseException(0, log_msg)
399406

400407
if not isinstance(output_dir, (str, Path)):
401-
log_msg = "'output_dir' should be 'str' or 'Path' type, not '%s'" % (
402-
type(output_dir)
408+
raise SABaseException(
409+
0, "'output_dir' should be 'str' or 'Path' type, not '%s'" %
410+
(type(output_dir))
403411
)
404-
raise SABaseException(0, log_msg)
405412

406413
sa_convert_project_type(input_dir, output_dir)

superannotate/input_converters/converters/coco_converters/coco_strategies.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ def __setup_conversion_algorithm(self):
3838
if self.direction == "to":
3939
if self.project_type == 'Pixel':
4040
self.conversion_algorithm = sa_pixel_to_coco_panoptic_segmentation
41-
elif self.project_type == 'Vector':
42-
pass
4341
else:
4442
self.conversion_algorithm = coco_panoptic_segmentation_to_sa_pixel
4543

@@ -130,8 +128,6 @@ def __setup_conversion_algorithm(self):
130128
if self.project_type == 'Pixel':
131129
if self.task == 'instance_segmentation':
132130
self.conversion_algorithm = coco_instance_segmentation_to_sa_pixel
133-
elif self.task == 'object_detection':
134-
raise ValueError('Method not implemented')
135131
elif self.project_type == 'Vector':
136132
if self.task == 'instance_segmentation':
137133
self.conversion_algorithm = coco_instance_segmentation_to_sa_vector

superannotate/input_converters/converters/dataloop_converters/dataloop_strategies.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ def __setup_conversion_algorithm(self):
2323
self.conversion_algorithm = dataloop_instance_segmentation_to_sa_vector
2424
elif self.task == 'vector_annotation':
2525
self.conversion_algorithm = dataloop_to_sa
26-
elif self.project_type == "Pixel":
27-
raise NotImplementedError("Doesn't support yet")
2826

2927
def __str__(self):
3028
return '{} object'.format(self.name)
3129

32-
def from_sa_format(self):
33-
pass
34-
3530
def to_sa_format(self):
3631
id_generator = self._make_id_generator()
3732
sa_jsons, classes_json = self.conversion_algorithm(

superannotate/input_converters/converters/googlecloud_converters/googlecloud_strategies.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,15 @@ def __setup_conversion_algorithm(self):
1818
else:
1919
if self.project_type == "Vector":
2020
if self.task == "object_detection":
21-
self.converion_algorithm = googlecloud_object_detection_to_sa_vector
22-
else:
23-
raise NotImplementedError("Doesn't support yet")
24-
elif self.project_type == "Pixel":
25-
raise NotImplementedError("Doesn't support yet")
21+
self.conversion_algorithm = googlecloud_object_detection_to_sa_vector
2622

2723
def __str__(self):
2824
return '{} object'.format(self.name)
2925

30-
def from_sa_format(self):
31-
pass
32-
3326
def to_sa_format(self):
3427
path = Path(self.export_root).joinpath(self.dataset_name + '.csv')
3528
id_generator = self._make_id_generator()
36-
sa_jsons, sa_classes = self.converion_algorithm(path, id_generator)
29+
sa_jsons, sa_classes = self.conversion_algorithm(path, id_generator)
3730
self.dump_output(sa_classes, sa_jsons)
3831

3932
def _make_id_generator(self):

superannotate/input_converters/converters/labelbox_converters/labelbox_strategies.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,23 @@ def __setup_conversion_algorithm(self):
1818
else:
1919
if self.project_type == "Vector":
2020
if self.task == "object_detection":
21-
self.converion_algorithm = labelbox_object_detection_to_sa_vector
21+
self.conversion_algorithm = labelbox_object_detection_to_sa_vector
2222
elif self.task == 'instance_segmentation':
23-
self.converion_algorithm = labelbox_instance_segmentation_to_sa_vector
23+
self.conversion_algorithm = labelbox_instance_segmentation_to_sa_vector
2424
elif self.task == 'vector_annotation':
25-
self.converion_algorithm = labelbox_to_sa
26-
elif self.project_type == "Pixel":
27-
raise NotImplementedError("Doesn't support yet")
25+
self.conversion_algorithm = labelbox_to_sa
2826

2927
def __str__(self):
3028
return '{} object'.format(self.name)
3129

32-
def from_sa_format(self):
33-
pass
34-
3530
def to_sa_format(self):
3631
json_data = json.load(
3732
open(os.path.join(self.export_root, self.dataset_name + '.json'))
3833
)
3934
id_generator = self._make_id_generator()
40-
sa_jsons, sa_classes = self.converion_algorithm(json_data, id_generator)
35+
sa_jsons, sa_classes = self.conversion_algorithm(
36+
json_data, id_generator
37+
)
4138
self.dump_output(sa_classes, sa_jsons)
4239

4340
def _make_id_generator(self):

superannotate/input_converters/converters/sagemaker_converters/sagemaker_strategies.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ def __setup_conversion_algorithm(self):
2626
if self.task == "instance_segmentation":
2727
self.conversion_algorithm = sagemaker_instance_segmentation_to_sa_pixel
2828

29-
def __str__(self):
30-
return '{} object'.format(self.name)
31-
32-
def from_sa_format(self):
33-
pass
29+
# def __str__(self):
30+
# return '{} object'.format(self.name)
3431

3532
def to_sa_format(self):
3633
sa_jsons, sa_classes, sa_masks = self.conversion_algorithm(

superannotate/input_converters/converters/supervisely_converters/supervisely_strategies.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ def __setup_conversion_algorithm(self):
3333
elif self.project_type == "Pixel":
3434
if self.task == 'instance_segmentation':
3535
self.conversion_algorithm = supervisely_instance_segmentation_to_sa_pixel
36-
else:
37-
raise NotImplementedError("Doesn't support yet")
3836

3937
def __str__(self):
4038
return '{} object'.format(self.name)
4139

42-
def from_sa_format(self):
43-
pass
44-
4540
def to_sa_format(self):
4641
id_generator = self._make_id_generator()
4742
sa_classes, classes_id_map = self._create_sa_classes(

superannotate/input_converters/converters/vgg_converters/vgg_strategies.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ def __setup_conversion_algorithm(self):
2222
self.conversion_algorithm = vgg_instance_segmentation_to_sa_vector
2323
elif self.task == 'vector_annotation':
2424
self.conversion_algorithm = vgg_to_sa
25-
elif self.project_type == "Pixel":
26-
raise NotImplementedError("Doesn't support yet")
2725

2826
def __str__(self):
2927
return '{} object'.format(self.name)
3028

31-
def from_sa_format(self):
32-
pass
33-
3429
def to_sa_format(self):
3530
json_data = self.get_file_list()
3631
id_generator = self._make_id_generator()

superannotate/input_converters/converters/voc_converters/voc_strategies.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,12 @@ def __setup_conversion_algorithm(self):
2424
elif self.task == "instance_segmentation":
2525
self.conversion_algorithm = voc_instance_segmentation_to_sa_vector
2626
elif self.project_type == "Pixel":
27-
if self.task == "object_detection":
28-
raise NotImplementedError("Doesn't support yet")
29-
elif self.task == "instance_segmentation":
27+
if self.task == "instance_segmentation":
3028
self.conversion_algorithm = voc_instance_segmentation_to_sa_pixel
3129

3230
def __str__(self):
3331
return '{} object'.format(self.name)
3432

35-
def from_sa_format(self):
36-
pass
37-
3833
def to_sa_format(self):
3934
sa_classes, sa_jsons, sa_masks = self.conversion_algorithm(
4035
self.export_root

superannotate/input_converters/converters/vott_converters/vott_strategies.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ def __setup_conversion_algorithm(self):
2222
self.conversion_algorithm = vott_instance_segmentation_to_sa_vector
2323
elif self.task == 'vector_annotation':
2424
self.conversion_algorithm = vott_to_sa
25-
elif self.project_type == "Pixel":
26-
raise NotImplementedError("Doesn't support yet")
2725

2826
def __str__(self):
2927
return '{} object'.format(self.name)
3028

31-
def from_sa_format(self):
32-
pass
33-
3429
def to_sa_format(self):
3530
json_data = self.get_file_list()
3631
id_generator = self._make_id_generator()

0 commit comments

Comments
 (0)