Skip to content

Commit

Permalink
Wrote integration tests for feature schema attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Kerr committed Dec 17, 2024
1 parent d95092f commit 10e9ce2
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
71 changes: 71 additions & 0 deletions libs/labelbox/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from labelbox.schema.data_row import DataRowMetadataField
from labelbox.schema.ontology_kind import OntologyKind
from labelbox.schema.user import User
from labelbox.schema.tool_building.types import FeatureSchemaAttribute


@pytest.fixture
Expand Down Expand Up @@ -552,6 +553,76 @@ def point():
)


@pytest.fixture
def auto_ocr_text_value_class():
return Classification(
class_type=Classification.Type.TEXT,
name="Auto OCR Text Value",
instructions="Text value for ocr bboxes",
scope=Classification.Scope.GLOBAL,
required=False,
attributes=[
FeatureSchemaAttribute(
attributeName="auto-ocr-text-value", attributeValue="true"
)
],
)


@pytest.fixture
def auto_ocr_bbox(auto_ocr_text_value_class):
return Tool(
tool=Tool.Type.BBOX,
name="Auto ocr bbox",
color="ff0000",
attributes=[
FeatureSchemaAttribute(
attributeName="auto-ocr", attributeValue="true"
)
],
classifications=[auto_ocr_text_value_class],
)


@pytest.fixture
def requires_connection_classification():
return Classification(
name="Requires connection radio",
instructions="Classification that requires a connection",
class_type=Classification.Type.RADIO,
attributes=[
FeatureSchemaAttribute(
attributeName="requires-connection", attributeValue="true"
)
],
options=[Option(value="A"), Option(value="B")],
)


@pytest.fixture
def requires_connection_classification_feature_schema(
client, requires_connection_classification
):
created_feature_schema = client.upsert_feature_schema(
requires_connection_classification.asdict()
)
yield created_feature_schema
client.delete_unused_feature_schema(
created_feature_schema.normalized["featureSchemaId"]
)


@pytest.fixture
def auto_ocr_bbox_feature_schema(client, auto_ocr_bbox):
created_feature_schema = client.upsert_feature_schema(
auto_ocr_bbox.asdict()
)
yield created_feature_schema
client.delete_unused_feature_schema(
created_feature_schema.normalized["featureSchemaId"]
)


@pytest.fixture
def feature_schema(client, point):
created_feature_schema = client.upsert_feature_schema(point.asdict())
Expand Down
26 changes: 26 additions & 0 deletions libs/labelbox/tests/integration/test_feature_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,29 @@ def test_does_not_include_used_feature_schema(client, feature_schema):
assert feature_schema_id not in unused_feature_schemas

client.delete_unused_ontology(ontology.uid)


def test_upsert_tool_with_attributes(auto_ocr_bbox_feature_schema):
auto_ocr_attributes = auto_ocr_bbox_feature_schema.normalized["attributes"]
auto_ocr_text_value_attributes = auto_ocr_bbox_feature_schema.normalized[
"classifications"
][0]["attributes"]
assert auto_ocr_attributes == [
{"attributeName": "auto-ocr", "attributeValue": "true"}
]
assert auto_ocr_text_value_attributes == [
{"attributeName": "auto-ocr-text-value", "attributeValue": "true"}
]


def test_upsert_classification_with_attributes(
requires_connection_classification_feature_schema,
):
requires_connection_attributes = (
requires_connection_classification_feature_schema.normalized[
"attributes"
]
)
assert requires_connection_attributes == [
{"attributeName": "requires-connection", "attributeValue": "true"}
]

0 comments on commit 10e9ce2

Please sign in to comment.