-
Notifications
You must be signed in to change notification settings - Fork 68
New methods to manage feature schemas and ontologies #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f0f8467
add methods to manage feature schemas
lgluszek 3cea973
formatting
lgluszek d4faa48
formatting
lgluszek 56583b5
rename normalized to feature_schema
lgluszek c728290
add function return types
lgluszek bd8831c
add get_unused_ontologies and get_unused_feature_schemas
lgluszek c8d63f6
add return types
lgluszek b3db0aa
Merge branch 'develop' into lgluszek/ontology-update
lgluszek 0903e72
add proper return type
lgluszek 6345182
Merge branch 'develop' into lgluszek/ontology-update
lgluszek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import pytest | ||
|
|
||
| from labelbox import Tool, MediaType | ||
|
|
||
| point = Tool( | ||
| tool=Tool.Type.POINT, | ||
| name="name", | ||
| color="#ff0000", | ||
| ) | ||
|
|
||
|
|
||
| def test_deletes_a_feature_schema(client): | ||
| tool = client.upsert_feature_schema(point.asdict()) | ||
|
|
||
| assert client.delete_unused_feature_schema( | ||
| tool.normalized['featureSchemaId']) is None | ||
|
|
||
|
|
||
| def test_cant_delete_already_deleted_feature_schema(client): | ||
| tool = client.upsert_feature_schema(point.asdict()) | ||
| feature_schema_id = tool.normalized['featureSchemaId'] | ||
|
|
||
| client.delete_unused_feature_schema(feature_schema_id) is None | ||
|
|
||
| with pytest.raises( | ||
| Exception, | ||
| match= | ||
| "Failed to delete the feature schema, message: Feature schema is already deleted" | ||
| ): | ||
| client.delete_unused_feature_schema(feature_schema_id) | ||
|
|
||
|
|
||
| def test_cant_delete_feature_schema_with_ontology(client): | ||
| tool = client.upsert_feature_schema(point.asdict()) | ||
| feature_schema_id = tool.normalized['featureSchemaId'] | ||
| ontology = client.create_ontology_from_feature_schemas( | ||
| name='ontology name', | ||
| feature_schema_ids=[feature_schema_id], | ||
| media_type=MediaType.Image) | ||
|
|
||
| with pytest.raises( | ||
| Exception, | ||
| match= | ||
| "Failed to delete the feature schema, message: Feature schema cannot be deleted because it is used in ontologies" | ||
| ): | ||
| client.delete_unused_feature_schema(feature_schema_id) | ||
|
|
||
| client.delete_unused_ontology(ontology.uid) | ||
| client.delete_unused_feature_schema(feature_schema_id) | ||
|
|
||
|
|
||
| def test_throws_an_error_if_feature_schema_to_delete_doesnt_exist(client): | ||
| with pytest.raises( | ||
| Exception, | ||
| match= | ||
| "Failed to delete the feature schema, message: Cannot find root schema node with feature schema id doesntexist" | ||
| ): | ||
| client.delete_unused_feature_schema("doesntexist") | ||
|
|
||
|
|
||
| def test_updates_a_feature_schema_title(client): | ||
| tool = client.upsert_feature_schema(point.asdict()) | ||
| feature_schema_id = tool.normalized['featureSchemaId'] | ||
| new_title = "new title" | ||
| updated_feature_schema = client.update_feature_schema_title( | ||
| feature_schema_id, new_title) | ||
|
|
||
| assert updated_feature_schema.normalized['name'] == new_title | ||
|
|
||
| client.delete_unused_feature_schema(feature_schema_id) | ||
|
|
||
|
|
||
| def test_throws_an_error_when_updating_a_feature_schema_with_empty_title( | ||
| client): | ||
| tool = client.upsert_feature_schema(point.asdict()) | ||
| feature_schema_id = tool.normalized['featureSchemaId'] | ||
|
|
||
| with pytest.raises(Exception): | ||
| client.update_feature_schema_title(feature_schema_id, "") | ||
|
|
||
| client.delete_unused_feature_schema(feature_schema_id) | ||
|
|
||
|
|
||
| def test_throws_an_error_when_updating_not_existing_feature_schema(client): | ||
| with pytest.raises(Exception): | ||
| client.update_feature_schema_title("doesntexist", "new title") | ||
|
|
||
|
|
||
| def test_creates_a_new_feature_schema(client): | ||
| created_feature_schema = client.upsert_feature_schema(point.asdict()) | ||
|
|
||
| assert created_feature_schema.uid is not None | ||
|
|
||
| client.delete_unused_feature_schema( | ||
| created_feature_schema.normalized['featureSchemaId']) | ||
|
|
||
|
|
||
| def test_updates_a_feature_schema(client): | ||
| tool = Tool( | ||
| tool=Tool.Type.POINT, | ||
| name="name", | ||
| color="#ff0000", | ||
| ) | ||
| created_feature_schema = client.upsert_feature_schema(tool.asdict()) | ||
| tool_to_update = Tool( | ||
| tool=Tool.Type.POINT, | ||
| name="new name", | ||
| color="#ff0000", | ||
| feature_schema_id=created_feature_schema.normalized['featureSchemaId'], | ||
| ) | ||
| updated_feature_schema = client.upsert_feature_schema( | ||
| tool_to_update.asdict()) | ||
|
|
||
| assert updated_feature_schema.normalized['name'] == "new name" | ||
|
|
||
|
|
||
| def test_does_not_include_used_feature_schema(client): | ||
| tool = client.upsert_feature_schema(point.asdict()) | ||
| feature_schema_id = tool.normalized['featureSchemaId'] | ||
| ontology = client.create_ontology_from_feature_schemas( | ||
| name='ontology name', | ||
| feature_schema_ids=[feature_schema_id], | ||
| media_type=MediaType.Image) | ||
| unused_feature_schemas = client.get_unused_feature_schemas() | ||
|
|
||
| assert feature_schema_id not in unused_feature_schemas | ||
|
|
||
| client.delete_unused_ontology(ontology.uid) | ||
| client.delete_unused_feature_schema(feature_schema_id) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to not use fixtures for tests, because the feature schema class does not have a "deletable" interface. Schema nodes have a "deleted" property, but we can't create such fixtures.