Skip to content

Commit b046108

Browse files
author
Val Brodsky
committed
Fix test for empty ontology
1 parent f468aa0 commit b046108

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def is_chat_evaluation(self) -> bool:
149149
def is_auto_data_generation(self) -> bool:
150150
return (self.upload_type == UploadType.Auto) # type: ignore
151151

152+
# we test not pnly the project ontology is None, but also a default empty ontology that we create when we attach a labeling front end in createLabelingFrontendOptions
153+
def is_empty_ontology(self) -> bool:
154+
ontology = self.ontology() # type: ignore
155+
return ontology is None or (len(ontology.tools()) == 0 and
156+
len(ontology.classifications()) == 0)
157+
152158
def project_model_configs(self):
153159
query_str = """query ProjectModelConfigsPyApi($id: ID!) {
154160
project(where: {id : $id}) {
@@ -791,6 +797,9 @@ def connect_ontology(self, ontology) -> None:
791797
"classifications": []
792798
})
793799

800+
if not self.is_empty_ontology():
801+
raise ValueError("Ontology already connected to project.")
802+
794803
query_str = """mutation ConnectOntologyPyApi($projectId: ID!, $ontologyId: ID!){
795804
project(where: {id: $projectId}) {connectOntology(ontologyId: $ontologyId) {id}}}"""
796805
self.client.execute(query_str, {

libs/labelbox/tests/integration/test_project_setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ def test_project_editor_setup(client, project, rand_gen):
6868
] == [ontology_name]
6969

7070

71-
def test_project_editor_setup_cant_call_multiple_times(client, project,
72-
rand_gen):
71+
def test_project_connect_ontology_cant_call_multiple_times(
72+
client, project, rand_gen):
7373
ontology_name = f"test_project_editor_setup_ontology_name-{rand_gen(str)}"
7474
ontology = client.create_ontology(ontology_name, simple_ontology())
7575
project.connect_ontology(ontology)
76-
with pytest.raises(ResourceConflict):
76+
with pytest.raises(ValueError):
7777
project.connect_ontology(ontology)

0 commit comments

Comments
 (0)