Skip to content

Commit c578c48

Browse files
committed
Added integration test test_feature_schema_is_archived
1 parent a639533 commit c578c48

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

labelbox/client.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from labelbox.schema.role import Role
3737
from labelbox.schema.slice import CatalogSlice, ModelSlice
3838
from labelbox.schema.queue_mode import QueueMode
39-
from labelbox.schema.ontology import Ontology
39+
from labelbox.schema.ontology import Ontology, DeleteFeatureFromOntologyResult
4040

4141
from labelbox.schema.media_type import MediaType, get_media_type_validation_error
4242

@@ -45,11 +45,6 @@
4545
_LABELBOX_API_KEY = "LABELBOX_API_KEY"
4646

4747

48-
class DeleteFeatureFromOntologyResult:
49-
archived: bool
50-
deleted: bool
51-
52-
5348
class Client:
5449
""" A Labelbox client.
5550

labelbox/schema/ontology.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
from labelbox.exceptions import InconsistentOntologyException
1212
from labelbox.orm.db_object import DbObject
1313
from labelbox.orm.model import Field, Relationship
14+
import json
1415

1516
FeatureSchemaId: Type[str] = constr(min_length=25, max_length=25)
1617
SchemaId: Type[str] = constr(min_length=25, max_length=25)
1718

1819

20+
class DeleteFeatureFromOntologyResult:
21+
archived: bool
22+
deleted: bool
23+
24+
def __str__(self):
25+
return "<%s %s>" % (self.__class__.__name__.split(".")[-1],
26+
json.dumps(self.__dict__))
27+
28+
1929
class FeatureSchema(DbObject):
2030
name = Field.String("name")
2131
color = Field.String("name")

tests/integration/test_ontology.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@
55
import json
66
import time
77

8-
9-
def test_is_feature_schema_archived(client, ontology):
8+
def test_feature_schema_is_not_archived(client, ontology):
109
feature_schema_to_check = ontology.normalized['tools'][0]
1110
result = client.is_feature_schema_archived(
1211
ontology.uid, feature_schema_to_check['featureSchemaId'])
1312
assert result == False
1413

1514

15+
def test_feature_schema_is_archived(client, configured_project_with_label):
16+
project, _, _, label = configured_project_with_label
17+
ontology = project.ontology()
18+
feature_schema_id = ontology.normalized['tools'][0]['featureSchemaId']
19+
result = client.delete_feature_schema_from_ontology(ontology.uid,
20+
feature_schema_id)
21+
assert result.archived == True and result.deleted == False
22+
assert client.is_feature_schema_archived(ontology.uid,
23+
feature_schema_id) == True
24+
25+
1626
def test_is_feature_schema_archived_for_non_existing_feature_schema(
1727
client, ontology):
1828
with pytest.raises(
@@ -21,7 +31,6 @@ def test_is_feature_schema_archived_for_non_existing_feature_schema(
2131
client.is_feature_schema_archived(ontology.uid,
2232
'invalid-feature-schema-id')
2333

24-
2534
def test_is_feature_schema_archived_for_non_existing_ontology(client, ontology):
2635
feature_schema_to_unarchive = ontology.normalized['tools'][0]
2736
with pytest.raises(
@@ -31,7 +40,6 @@ def test_is_feature_schema_archived_for_non_existing_ontology(client, ontology):
3140
client.is_feature_schema_archived(
3241
'invalid-ontology', feature_schema_to_unarchive['featureSchemaId'])
3342

34-
3543
def test_delete_tool_feature_from_ontology(client, ontology):
3644
feature_schema_to_delete = ontology.normalized['tools'][0]
3745
assert len(ontology.normalized['tools']) == 2
@@ -42,7 +50,6 @@ def test_delete_tool_feature_from_ontology(client, ontology):
4250
updatedOntology = client.get_ontology(ontology.uid)
4351
assert len(updatedOntology.normalized['tools']) == 1
4452

45-
4653
@pytest.mark.skip(reason="normalized ontology contains Relationship, "
4754
"which is not finalized yet. introduce this back when"
4855
"Relationship feature is complete and we introduce"
@@ -51,14 +58,12 @@ def test_from_project_ontology(project) -> None:
5158
o = OntologyBuilder.from_project(project)
5259
assert o.asdict() == project.ontology().normalized
5360

54-
5561
point = Tool(
5662
tool=Tool.Type.POINT,
5763
name="name",
5864
color="#ff0000",
5965
)
6066

61-
6267
def test_deletes_an_ontology(client):
6368
tool = client.upsert_feature_schema(point.asdict())
6469
feature_schema_id = tool.normalized['featureSchemaId']
@@ -71,7 +76,6 @@ def test_deletes_an_ontology(client):
7176

7277
client.delete_unused_feature_schema(feature_schema_id)
7378

74-
7579
def test_cant_delete_an_ontology_with_project(client):
7680
project = client.create_project(name="test project",
7781
media_type=MediaType.Image)
@@ -94,7 +98,6 @@ def test_cant_delete_an_ontology_with_project(client):
9498
client.delete_unused_ontology(ontology.uid)
9599
client.delete_unused_feature_schema(feature_schema_id)
96100

97-
98101
def test_cant_delete_an_ontology_that_doesnt_exist(client):
99102
with pytest.raises(
100103
Exception,
@@ -103,7 +106,6 @@ def test_cant_delete_an_ontology_that_doesnt_exist(client):
103106
):
104107
client.delete_unused_ontology("doesntexist")
105108

106-
107109
def test_inserts_a_feature_schema_at_given_position(client):
108110
tool1 = {'tool': 'polygon', 'name': 'tool1', 'color': 'blue'}
109111
tool2 = {'tool': 'polygon', 'name': 'tool2', 'color': 'blue'}
@@ -121,7 +123,6 @@ def test_inserts_a_feature_schema_at_given_position(client):
121123

122124
client.delete_unused_ontology(ontology.uid)
123125

124-
125126
def test_moves_already_added_feature_schema_in_ontology(client):
126127
tool1 = {'tool': 'polygon', 'name': 'tool1', 'color': 'blue'}
127128
ontology_normalized_json = {"tools": [tool1], "classifications": []}
@@ -144,7 +145,6 @@ def test_moves_already_added_feature_schema_in_ontology(client):
144145

145146
client.delete_unused_ontology(ontology.uid)
146147

147-
148148
def test_does_not_include_used_ontologies(client):
149149
tool = client.upsert_feature_schema(point.asdict())
150150
feature_schema_id = tool.normalized['featureSchemaId']
@@ -163,14 +163,12 @@ def test_does_not_include_used_ontologies(client):
163163
client.delete_unused_ontology(ontology_with_project.uid)
164164
client.delete_unused_feature_schema(feature_schema_id)
165165

166-
167166
def _get_attr_stringify_json(obj, attr):
168167
value = getattr(obj, attr.name)
169168
if attr.field_type.name.lower() == "json":
170169
return json.dumps(value, sort_keys=True)
171170
return value
172171

173-
174172
def test_feature_schema_create_read(client, rand_gen):
175173
name = f"test-root-schema-{rand_gen(str)}"
176174
feature_schema_cat_normalized = {
@@ -199,7 +197,6 @@ def test_feature_schema_create_read(client, rand_gen):
199197
attr) == _get_attr_stringify_json(
200198
queried_feature_schema, attr)
201199

202-
203200
def test_ontology_create_read(client, rand_gen):
204201
ontology_name = f"test-ontology-{rand_gen(str)}"
205202
tool_name = f"test-ontology-tool-{rand_gen(str)}"

0 commit comments

Comments
 (0)