Skip to content

Commit 3895c9b

Browse files
author
Val Brodsky
committed
More updates
1 parent a98044c commit 3895c9b

File tree

3 files changed

+100
-51
lines changed

3 files changed

+100
-51
lines changed

libs/labelbox/tests/conftest.py

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010
from labelbox.schema.project import Project
1111
import requests
12+
from labelbox.schema.ontology import Ontology
1213
import pytest
1314
from types import SimpleNamespace
1415
from typing import Type
@@ -1160,15 +1161,26 @@ def teardown_project_labels_ontology_feature_schemas(project: Project):
11601161
ontology = project.ontology()
11611162
ontology_id = ontology.uid
11621163
client = project.client
1163-
1164-
# featureSchemaIds = [tool.feature_schema_id for tool in ontology_builder.tools]
11651164
classification_feature_schema_ids = [
1166-
feature["featureSchemaId"]
1165+
feature["schemaNodeId"]
11671166
for feature in ontology.normalized["classifications"]
1167+
] + [
1168+
option["featureSchemaId"]
1169+
for feature in ontology.normalized["classifications"]
1170+
for option in feature.get("options", [])
11681171
]
1172+
11691173
tool_feature_schema_ids = [
1170-
feature["featureSchemaId"]
1171-
for feature in ontology.normalized["tools"]
1174+
feature["schemaNodeId"] for feature in ontology.normalized["tools"]
1175+
] + [
1176+
classification["featureSchemaId"]
1177+
for tool in ontology.normalized["tools"]
1178+
for classification in tool.get("classifications", [])
1179+
] + [
1180+
option["featureSchemaId"]
1181+
for tool in ontology.normalized["tools"]
1182+
for classification in tool.get("classifications", [])
1183+
for option in classification.get("options", [])
11721184
]
11731185

11741186
feature_schema_ids = classification_feature_schema_ids + tool_feature_schema_ids
@@ -1179,9 +1191,63 @@ def teardown_project_labels_ontology_feature_schemas(project: Project):
11791191
project.delete()
11801192
client.delete_unused_ontology(ontology_id)
11811193
for feature_schema_id in feature_schema_ids:
1182-
project.client.delete_unused_feature_schema(feature_schema_id)
1194+
try:
1195+
project.client.delete_unused_feature_schema(feature_schema_id)
1196+
except LabelboxError as e:
1197+
print(
1198+
f"Failed to delete feature schema {feature_schema_id}: {e}")
1199+
1200+
@staticmethod
1201+
def teardown_ontology_feature_schemas(ontology: Ontology):
1202+
"""
1203+
Call this function to release project, labels, ontology and feature schemas in fixture teardown
1204+
1205+
NOTE: exception handling is not required as this is a fixture teardown
1206+
"""
1207+
ontology_id = ontology.uid
1208+
client = ontology.client
1209+
classification_feature_schema_ids = [
1210+
feature["featureSchemaId"]
1211+
for feature in ontology.normalized["classifications"]
1212+
] + [
1213+
option["featureSchemaId"]
1214+
for feature in ontology.normalized["classifications"]
1215+
for option in feature.get("options", [])
1216+
]
1217+
1218+
tool_feature_schema_ids = [
1219+
feature["schemaNodeId"] for feature in ontology.normalized["tools"]
1220+
] + [
1221+
classification["featureSchemaId"]
1222+
for tool in ontology.normalized["tools"]
1223+
for classification in tool.get("classifications", [])
1224+
] + [
1225+
option["featureSchemaId"]
1226+
for tool in ontology.normalized["tools"]
1227+
for classification in tool.get("classifications", [])
1228+
for option in classification.get("options", [])
1229+
]
1230+
1231+
feature_schema_ids = classification_feature_schema_ids + tool_feature_schema_ids
1232+
1233+
client.delete_unused_ontology(ontology_id)
1234+
for feature_schema_id in feature_schema_ids:
1235+
try:
1236+
project.client.delete_unused_feature_schema(feature_schema_id)
1237+
except LabelboxError as e:
1238+
print(
1239+
f"Failed to delete feature schema {feature_schema_id}: {e}")
1240+
1241+
1242+
class ModuleTearDownHelpers(TearDownHelpers):
1243+
...
11831244

11841245

11851246
@pytest.fixture
11861247
def teardown_helpers():
11871248
return TearDownHelpers()
1249+
1250+
1251+
@pytest.fixture(scope='module')
1252+
def module_teardown_helpers():
1253+
return TearDownHelpers()

libs/labelbox/tests/data/annotation_import/conftest.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ def _create_project(
716716
)
717717

718718
project.connect_ontology(ontology)
719-
720719
data_row_data = []
721720

722721
for _ in range(DATA_ROW_COUNT):
@@ -741,15 +740,12 @@ def _create_project(
741740

742741

743742
@pytest.fixture
744-
def configured_project(
745-
client: Client,
746-
rand_gen,
747-
data_row_json_by_media_type,
748-
request: FixtureRequest,
749-
normalized_ontology_by_media_type,
750-
export_v2_test_helpers,
751-
llm_prompt_response_creation_dataset_with_data_row,
752-
):
743+
def configured_project(client: Client, rand_gen, data_row_json_by_media_type,
744+
request: FixtureRequest,
745+
normalized_ontology_by_media_type,
746+
export_v2_test_helpers,
747+
llm_prompt_response_creation_dataset_with_data_row,
748+
teardown_helpers):
753749
"""Configure project for test. Request.param will contain the media type if not present will use Image MediaType. The project will have 10 data rows."""
754750

755751
media_type = getattr(request, "param", MediaType.Image)
@@ -786,23 +782,18 @@ def configured_project(
786782

787783
yield project
788784

789-
project.delete()
785+
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)
790786

791787
if dataset:
792788
dataset.delete()
793789

794-
client.delete_unused_ontology(ontology.uid)
795-
796790

797791
@pytest.fixture()
798-
def configured_project_by_global_key(
799-
client: Client,
800-
rand_gen,
801-
data_row_json_by_media_type,
802-
request: FixtureRequest,
803-
normalized_ontology_by_media_type,
804-
export_v2_test_helpers,
805-
):
792+
def configured_project_by_global_key(client: Client, rand_gen,
793+
data_row_json_by_media_type,
794+
request: FixtureRequest,
795+
normalized_ontology_by_media_type,
796+
export_v2_test_helpers, teardown_helpers):
806797
"""Does the same thing as configured project but with global keys focus."""
807798

808799
media_type = getattr(request, "param", MediaType.Image)
@@ -838,22 +829,16 @@ def configured_project_by_global_key(
838829

839830
yield project
840831

841-
project.delete()
832+
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)
842833

843834
if dataset:
844835
dataset.delete()
845836

846-
client.delete_unused_ontology(ontology.uid)
847-
848837

849838
@pytest.fixture(scope="module")
850-
def module_project(
851-
client: Client,
852-
rand_gen,
853-
data_row_json_by_media_type,
854-
request: FixtureRequest,
855-
normalized_ontology_by_media_type,
856-
):
839+
def module_project(client: Client, rand_gen, data_row_json_by_media_type,
840+
request: FixtureRequest, normalized_ontology_by_media_type,
841+
module_teardown_helpers):
857842
"""Generates a image project that scopes to the test module(file). Used to reduce api calls."""
858843

859844
media_type = getattr(request, "param", MediaType.Image)
@@ -886,13 +871,12 @@ def module_project(
886871

887872
yield project
888873

889-
project.delete()
874+
module_teardown_helpers.teardown_project_labels_ontology_feature_schemas(
875+
project)
890876

891877
if dataset:
892878
dataset.delete()
893879

894-
client.delete_unused_ontology(ontology.uid)
895-
896880

897881
@pytest.fixture
898882
def prediction_id_mapping(request, normalized_ontology_by_media_type):
@@ -2245,6 +2229,7 @@ def to_pascal_case(name: str) -> str:
22452229
def find_data_row_filter(data_row):
22462230
return lambda dr: dr["data_row"]["id"] == data_row.uid
22472231

2232+
22482233
@pytest.fixture
22492234
def helpers():
22502235
return Helpers

libs/labelbox/tests/data/export/conftest.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,8 @@ def polygon_inference(prediction_id_mapping):
241241

242242

243243
@pytest.fixture
244-
def configured_project_with_ontology(
245-
client, initial_dataset, ontology, rand_gen, image_url
246-
):
244+
def configured_project_with_ontology(client, initial_dataset, ontology,
245+
rand_gen, image_url, teardown_helpers):
247246
dataset = initial_dataset
248247
project = client.create_project(
249248
name=rand_gen(str),
@@ -264,22 +263,21 @@ def configured_project_with_ontology(
264263
)
265264
project.data_row_ids = data_row_ids
266265
yield project
267-
project.delete()
266+
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)
268267

269268

270269
@pytest.fixture
271-
def configured_project_without_data_rows(client, ontology, rand_gen):
272-
project = client.create_project(
273-
name=rand_gen(str),
274-
description=rand_gen(str),
275-
queue_mode=QueueMode.Batch,
276-
)
270+
def configured_project_without_data_rows(client, ontology, rand_gen,
271+
teardown_helpers):
272+
project = client.create_project(name=rand_gen(str),
273+
description=rand_gen(str),
274+
queue_mode=QueueMode.Batch)
277275
editor = list(
278276
client.get_labeling_frontends(where=LabelingFrontend.name == "editor")
279277
)[0]
280278
project.setup(editor, ontology)
281279
yield project
282-
project.delete()
280+
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)
283281

284282

285283
@pytest.fixture

0 commit comments

Comments
 (0)