Skip to content

Commit 05e76d9

Browse files
committed
adding test + formatting
1 parent 24b2182 commit 05e76d9

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

labelbox/schema/bulk_import_request.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import requests
1212
from pydantic import BaseModel, validator
1313
from typing_extensions import Literal
14-
from typing import (Any, List, Optional, BinaryIO, Dict, Iterable, Tuple,
15-
Union, Type, Set)
14+
from typing import (Any, List, Optional, BinaryIO, Dict, Iterable, Tuple, Union,
15+
Type, Set)
1616

1717
import labelbox
1818
from labelbox import utils
@@ -79,14 +79,13 @@ def _send_create_file_command(
7979
response_data = response_json.get("data", None)
8080
if response_data is None:
8181
raise labelbox.exceptions.LabelboxError(
82-
"Failed to upload, message: %s" %
83-
response_json.get("errors", None))
82+
"Failed to upload, message: %s" % response_json.get("errors", None))
8483

8584
if not response_data.get("createBulkImportRequest", None):
8685
raise labelbox.exceptions.LabelboxError(
8786
"Failed to create BulkImportRequest, message: %s" %
88-
response_json.get("errors", None)
89-
or response_data.get("error", None))
87+
response_json.get("errors", None) or
88+
response_data.get("error", None))
9089

9190
return response_data
9291

@@ -435,8 +434,7 @@ def _validate_ndjson(lines: Iterable[Dict[str, Any]],
435434
f'{uuid} already used in this import job, '
436435
'must be unique for the project.')
437436
uids.add(uuid)
438-
except (pydantic.ValidationError, ValueError, TypeError,
439-
KeyError) as e:
437+
except (pydantic.ValidationError, ValueError, TypeError, KeyError) as e:
440438
raise labelbox.exceptions.MALValidationError(
441439
f"Invalid NDJson on line {idx}") from e
442440

@@ -520,6 +518,7 @@ class VideoSupported(BaseModel):
520518
#Base class for a special kind of union.
521519
# Compatible with pydantic. Improves error messages over a traditional union
522520
class SpecialUnion:
521+
523522
def __new__(cls, **kwargs):
524523
return cls.build(kwargs)
525524

@@ -657,11 +656,10 @@ def validate_answers(cls, value, field):
657656

658657
def validate_feature_schemas(self, valid_feature_schemas):
659658
#Test top level feature schema for this tool
660-
super(NDChecklist,
661-
self).validate_feature_schemas(valid_feature_schemas)
659+
super(NDChecklist, self).validate_feature_schemas(valid_feature_schemas)
662660
#Test the feature schemas provided to the answer field
663-
if len(set([answer.schemaId
664-
for answer in self.answers])) != len(self.answers):
661+
if len(set([answer.schemaId for answer in self.answers])) != len(
662+
self.answers):
665663
raise ValueError(
666664
f"Duplicated featureSchema found for checklist {self.uuid}")
667665
for answer in self.answers:
@@ -730,8 +728,7 @@ class NDPolygon(NDBaseTool):
730728
def is_geom_valid(cls, v):
731729
if len(v) < 3:
732730
raise ValueError(
733-
f"A polygon must have at least 3 points to be valid. Found {v}"
734-
)
731+
f"A polygon must have at least 3 points to be valid. Found {v}")
735732
return v
736733

737734

@@ -803,8 +800,7 @@ def is_valid_mask(cls, v):
803800
#Does the dtype matter? Can it be a float?
804801
if not isinstance(colors, (tuple, list)):
805802
raise ValueError(
806-
f"Received color that is not a list or tuple. Found : {colors}"
807-
)
803+
f"Received color that is not a list or tuple. Found : {colors}")
808804
elif len(colors) != 3:
809805
raise ValueError(
810806
f"Must provide RGB values for segmentation colors. Found : {colors}"
@@ -820,14 +816,15 @@ class NDTool(
820816
SpecialUnion,
821817
Type[Union[NDMask, # type: ignore
822818
NDTextEntity, NDPoint, NDRectangle, NDPolyline,
823-
NDPolygon, ]]):
819+
NDPolygon,]]):
824820
...
825821

826822

827823
class NDAnnotation(
828824
SpecialUnion,
829825
Type[Union[NDTool, # type: ignore
830826
NDClassification]]):
827+
831828
@classmethod
832829
def build(cls: Any, data) -> "NDBase":
833830
if not isinstance(data, dict):

tests/integration/bulk_import/test_bulk_import_request.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,12 @@ def test_wait_till_done(rectangle_inference, configured_project):
147147
def assert_file_content(url: str, predictions):
148148
response = requests.get(url)
149149
assert response.text == ndjson.dumps(predictions)
150+
151+
152+
def test_delete(configured_project, predictions):
153+
name = str(uuid.uuid4())
154+
155+
bulk_import_request = configured_project.upload_annotations(
156+
name=name, annotations=predictions)
157+
bulk_import_request.wait_til_done()
158+
bulk_import_request.delete()

0 commit comments

Comments
 (0)