Skip to content

Commit 3cea973

Browse files
committed
formatting
1 parent f0f8467 commit 3cea973

File tree

4 files changed

+75
-60
lines changed

4 files changed

+75
-60
lines changed

labelbox/client.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,8 @@ def delete_unused_feature_schema(self, feature_schema_id: str):
911911
>>> client.delete_unused_feature_schema("cleabc1my012ioqvu5anyaabc")
912912
"""
913913

914-
endpoint = self.rest_endpoint + "/feature-schemas/" + urllib.parse.quote(feature_schema_id)
914+
endpoint = self.rest_endpoint + "/feature-schemas/" + urllib.parse.quote(
915+
feature_schema_id)
915916
response = requests.delete(
916917
endpoint,
917918
headers=self.headers,
@@ -931,7 +932,8 @@ def delete_unused_ontology(self, ontology_id: str):
931932
>>> client.delete_unused_ontology("cleabc1my012ioqvu5anyaabc")
932933
"""
933934

934-
endpoint = self.rest_endpoint + "/ontologies/" + urllib.parse.quote(ontology_id)
935+
endpoint = self.rest_endpoint + "/ontologies/" + urllib.parse.quote(
936+
ontology_id)
935937
response = requests.delete(
936938
endpoint,
937939
headers=self.headers,
@@ -954,7 +956,8 @@ def update_feature_schema_title(self, feature_schema_id: str, title: str):
954956
>>> client.update_feature_schema_title("cleabc1my012ioqvu5anyaabc", "New Title")
955957
"""
956958

957-
endpoint = self.rest_endpoint + "/feature-schemas/" + urllib.parse.quote(feature_schema_id) + '/definition'
959+
endpoint = self.rest_endpoint + "/feature-schemas/" + urllib.parse.quote(
960+
feature_schema_id) + '/definition'
958961
response = requests.patch(
959962
endpoint,
960963
headers=self.headers,
@@ -1001,7 +1004,8 @@ def upsert_feature_schema(self, normalized: Dict):
10011004
"Failed to upsert the feature schema, message: " +
10021005
str(response.json()['message']))
10031006

1004-
def insert_feature_schema_into_ontology(self, feature_schema_id: str, ontology_id: str, position: int):
1007+
def insert_feature_schema_into_ontology(self, feature_schema_id: str,
1008+
ontology_id: str, position: int):
10051009
"""
10061010
Inserts a feature schema into an ontology. If the feature schema is already in the ontology,
10071011
it will be moved to the new position.
@@ -1014,16 +1018,17 @@ def insert_feature_schema_into_ontology(self, feature_schema_id: str, ontology_i
10141018
"""
10151019

10161020
endpoint = self.rest_endpoint + '/ontologies/' + urllib.parse.quote(
1017-
ontology_id) + "/feature-schemas/" + urllib.parse.quote(feature_schema_id)
1021+
ontology_id) + "/feature-schemas/" + urllib.parse.quote(
1022+
feature_schema_id)
10181023
response = requests.post(
10191024
endpoint,
10201025
headers=self.headers,
10211026
json={"position": position},
10221027
)
10231028
if response.status_code != requests.codes.created:
10241029
raise labelbox.exceptions.LabelboxError(
1025-
"Failed to insert the feature schema into the ontology, message: " +
1026-
str(response.json()['message']))
1030+
"Failed to insert the feature schema into the ontology, message: "
1031+
+ str(response.json()['message']))
10271032

10281033
def create_ontology(self, name, normalized, media_type=None) -> Ontology:
10291034
"""

tests/integration/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ def rest_url(environ: str) -> str:
7171
elif environ == Environ.STAGING:
7272
return 'https://api.lb-stage.xyz/api/v1'
7373
elif environ == Environ.CUSTOM:
74-
graphql_api_endpoint = os.environ.get(
75-
'LABELBOX_TEST_REST_API_ENDPOINT')
74+
graphql_api_endpoint = os.environ.get('LABELBOX_TEST_REST_API_ENDPOINT')
7675
if graphql_api_endpoint is None:
7776
raise Exception(f"Missing LABELBOX_TEST_REST_API_ENDPOINT")
7877
return graphql_api_endpoint
@@ -146,7 +145,10 @@ def __init__(self, environ: str) -> None:
146145
api_url = graphql_url(environ)
147146
api_key = testing_api_key(environ)
148147
rest_endpoint = rest_url(environ)
149-
super().__init__(api_key, api_url, enable_experimental=True, rest_endpoint=rest_endpoint)
148+
super().__init__(api_key,
149+
api_url,
150+
enable_experimental=True,
151+
rest_endpoint=rest_endpoint)
150152
self.queries = []
151153

152154
def execute(self, query=None, params=None, check_naming=True, **kwargs):

tests/integration/test_feature_schema.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
def test_deletes_a_feature_schema(client):
1313
tool = client.upsert_feature_schema(point.asdict())
1414

15-
assert client.delete_unused_feature_schema(tool.normalized['featureSchemaId']) is None
15+
assert client.delete_unused_feature_schema(
16+
tool.normalized['featureSchemaId']) is None
1617

1718

1819
def test_cant_delete_already_deleted_feature_schema(client):
@@ -21,8 +22,11 @@ def test_cant_delete_already_deleted_feature_schema(client):
2122

2223
client.delete_unused_feature_schema(feature_schema_id) is None
2324

24-
with pytest.raises(Exception,
25-
match="Failed to delete the feature schema, message: Feature schema is already deleted"):
25+
with pytest.raises(
26+
Exception,
27+
match=
28+
"Failed to delete the feature schema, message: Feature schema is already deleted"
29+
):
2630
client.delete_unused_feature_schema(feature_schema_id)
2731

2832

@@ -34,32 +38,40 @@ def test_cant_delete_feature_schema_with_ontology(client):
3438
feature_schema_ids=[feature_schema_id],
3539
media_type=MediaType.Image)
3640

37-
with pytest.raises(Exception,
38-
match="Failed to delete the feature schema, message: Feature schema cannot be deleted because it is used in ontologies"):
41+
with pytest.raises(
42+
Exception,
43+
match=
44+
"Failed to delete the feature schema, message: Feature schema cannot be deleted because it is used in ontologies"
45+
):
3946
client.delete_unused_feature_schema(feature_schema_id)
4047

4148
client.delete_unused_ontology(ontology.uid)
4249
client.delete_unused_feature_schema(feature_schema_id)
4350

4451

4552
def test_throws_an_error_if_feature_schema_to_delete_doesnt_exist(client):
46-
with pytest.raises(Exception,
47-
match="Failed to delete the feature schema, message: Cannot find root schema node with feature schema id doesntexist"):
53+
with pytest.raises(
54+
Exception,
55+
match=
56+
"Failed to delete the feature schema, message: Cannot find root schema node with feature schema id doesntexist"
57+
):
4858
client.delete_unused_feature_schema("doesntexist")
4959

5060

5161
def test_updates_a_feature_schema_title(client):
5262
tool = client.upsert_feature_schema(point.asdict())
5363
feature_schema_id = tool.normalized['featureSchemaId']
5464
new_title = "new title"
55-
updated_feature_schema = client.update_feature_schema_title(feature_schema_id, new_title)
65+
updated_feature_schema = client.update_feature_schema_title(
66+
feature_schema_id, new_title)
5667

5768
assert updated_feature_schema.normalized['name'] == new_title
5869

5970
client.delete_unused_feature_schema(feature_schema_id)
6071

6172

62-
def test_throws_an_error_when_updating_a_feature_schema_with_empty_title(client):
73+
def test_throws_an_error_when_updating_a_feature_schema_with_empty_title(
74+
client):
6375
tool = client.upsert_feature_schema(point.asdict())
6476
feature_schema_id = tool.normalized['featureSchemaId']
6577

@@ -79,7 +91,8 @@ def test_creates_a_new_feature_schema(client):
7991

8092
assert created_feature_schema.uid is not None
8193

82-
client.delete_unused_feature_schema(created_feature_schema.normalized['featureSchemaId'])
94+
client.delete_unused_feature_schema(
95+
created_feature_schema.normalized['featureSchemaId'])
8396

8497

8598
def test_updates_a_feature_schema(client):
@@ -95,7 +108,7 @@ def test_updates_a_feature_schema(client):
95108
color="#ff0000",
96109
feature_schema_id=created_feature_schema.normalized['featureSchemaId'],
97110
)
98-
updated_feature_schema = client.upsert_feature_schema(tool_to_update.asdict())
111+
updated_feature_schema = client.upsert_feature_schema(
112+
tool_to_update.asdict())
99113

100-
assert updated_feature_schema.normalized[
101-
'name'] == "new name"
114+
assert updated_feature_schema.normalized['name'] == "new name"

tests/integration/test_ontology.py

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88

99
@pytest.mark.skip(reason="normalized ontology contains Relationship, "
10-
"which is not finalized yet. introduce this back when"
11-
"Relationship feature is complete and we introduce"
12-
"a Relationship object to the ontology that we can parse")
10+
"which is not finalized yet. introduce this back when"
11+
"Relationship feature is complete and we introduce"
12+
"a Relationship object to the ontology that we can parse")
1313
def test_from_project_ontology(project) -> None:
1414
o = OntologyBuilder.from_project(project)
1515
assert o.asdict() == project.ontology().normalized
@@ -36,7 +36,8 @@ def test_deletes_an_ontology(client):
3636

3737

3838
def test_cant_delete_an_ontology_with_project(client):
39-
project = client.create_project(name="test project", media_type=MediaType.Image)
39+
project = client.create_project(name="test project",
40+
media_type=MediaType.Image)
4041
tool = client.upsert_feature_schema(point.asdict())
4142
feature_schema_id = tool.normalized['featureSchemaId']
4243
ontology = client.create_ontology_from_feature_schemas(
@@ -45,8 +46,11 @@ def test_cant_delete_an_ontology_with_project(client):
4546
media_type=MediaType.Image)
4647
project.setup_editor(ontology)
4748

48-
with pytest.raises(Exception,
49-
match="Failed to delete the ontology, message: Cannot delete an ontology connected to a project. The ontology is connected to projects: " + project.uid):
49+
with pytest.raises(
50+
Exception,
51+
match=
52+
"Failed to delete the ontology, message: Cannot delete an ontology connected to a project. The ontology is connected to projects: "
53+
+ project.uid):
5054
client.delete_unused_ontology(ontology.uid)
5155

5256
project.delete()
@@ -55,60 +59,51 @@ def test_cant_delete_an_ontology_with_project(client):
5559

5660

5761
def test_cant_delete_an_ontology_that_doesnt_exist(client):
58-
with pytest.raises(Exception,
59-
match="Failed to delete the ontology, message: Failed to find ontology by id: doesntexist"):
62+
with pytest.raises(
63+
Exception,
64+
match=
65+
"Failed to delete the ontology, message: Failed to find ontology by id: doesntexist"
66+
):
6067
client.delete_unused_ontology("doesntexist")
6168

6269

6370
def test_inserts_a_feature_schema_at_given_position(client):
64-
tool1 = {
65-
'tool': 'polygon',
66-
'name': 'tool1',
67-
'color': 'blue'
68-
}
69-
tool2 = {
70-
'tool': 'polygon',
71-
'name': 'tool2',
72-
'color': 'blue'
73-
}
74-
ontology_normalized_json = {
75-
"tools": [tool1, tool2],
76-
"classifications": []
77-
}
71+
tool1 = {'tool': 'polygon', 'name': 'tool1', 'color': 'blue'}
72+
tool2 = {'tool': 'polygon', 'name': 'tool2', 'color': 'blue'}
73+
ontology_normalized_json = {"tools": [tool1, tool2], "classifications": []}
7874
ontology = client.create_ontology(name="ontology",
7975
normalized=ontology_normalized_json,
8076
media_type=MediaType.Image)
8177
created_feature_schema = client.upsert_feature_schema(point.asdict())
82-
client.insert_feature_schema_into_ontology(created_feature_schema.normalized['featureSchemaId'], ontology.uid, 1)
78+
client.insert_feature_schema_into_ontology(
79+
created_feature_schema.normalized['featureSchemaId'], ontology.uid, 1)
8380
ontology = client.get_ontology(ontology.uid)
8481

85-
assert ontology.normalized['tools'][1]['schemaNodeId'] == created_feature_schema.normalized['schemaNodeId']
82+
assert ontology.normalized['tools'][1][
83+
'schemaNodeId'] == created_feature_schema.normalized['schemaNodeId']
8684

8785
client.delete_unused_ontology(ontology.uid)
8886

8987

9088
def test_moves_already_added_feature_schema_in_ontology(client):
91-
tool1 = {
92-
'tool': 'polygon',
93-
'name': 'tool1',
94-
'color': 'blue'
95-
}
96-
ontology_normalized_json = {
97-
"tools": [tool1],
98-
"classifications": []
99-
}
89+
tool1 = {'tool': 'polygon', 'name': 'tool1', 'color': 'blue'}
90+
ontology_normalized_json = {"tools": [tool1], "classifications": []}
10091
ontology = client.create_ontology(name="ontology",
10192
normalized=ontology_normalized_json,
10293
media_type=MediaType.Image)
10394
created_feature_schema = client.upsert_feature_schema(point.asdict())
10495
feature_schema_id = created_feature_schema.normalized['featureSchemaId']
105-
client.insert_feature_schema_into_ontology(feature_schema_id, ontology.uid, 1)
96+
client.insert_feature_schema_into_ontology(feature_schema_id, ontology.uid,
97+
1)
10698
ontology = client.get_ontology(ontology.uid)
107-
assert ontology.normalized['tools'][1]['schemaNodeId'] == created_feature_schema.normalized['schemaNodeId']
108-
client.insert_feature_schema_into_ontology(feature_schema_id, ontology.uid, 0)
99+
assert ontology.normalized['tools'][1][
100+
'schemaNodeId'] == created_feature_schema.normalized['schemaNodeId']
101+
client.insert_feature_schema_into_ontology(feature_schema_id, ontology.uid,
102+
0)
109103
ontology = client.get_ontology(ontology.uid)
110104

111-
assert ontology.normalized['tools'][0]['schemaNodeId'] == created_feature_schema.normalized['schemaNodeId']
105+
assert ontology.normalized['tools'][0][
106+
'schemaNodeId'] == created_feature_schema.normalized['schemaNodeId']
112107

113108
client.delete_unused_ontology(ontology.uid)
114109

0 commit comments

Comments
 (0)