Skip to content

Commit

Permalink
missing fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-chang committed Mar 20, 2024
1 parent b0e65a6 commit 3ca3781
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions libs/labelbox/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import re
import uuid
import time
import requests
from types import SimpleNamespace
from enum import Enum
Expand All @@ -22,6 +23,20 @@
from labelbox.schema.queue_mode import QueueMode
from labelbox import Client

from labelbox import Dataset, DataRow
from labelbox import LabelingFrontend
from labelbox import OntologyBuilder, Tool, Option, Classification, MediaType
from labelbox.orm import query
from labelbox.pagination import PaginatedCollection
from labelbox.schema.annotation_import import LabelImport
from labelbox.schema.catalog import Catalog
from labelbox.schema.enums import AnnotationImportState
from labelbox.schema.invite import Invite
from labelbox.schema.quality_mode import QualityMode
from labelbox.schema.queue_mode import QueueMode
from labelbox.schema.user import User
from labelbox import Client

IMG_URL = "https://picsum.photos/200/300.jpg"
MASKABLE_IMG_URL = "https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg"
SMALL_DATASET_URL = "https://storage.googleapis.com/lb-artifacts-testing-public/sdk_integration_test/potato.jpeg"
Expand Down Expand Up @@ -576,3 +591,77 @@ def organization(client):
for invite in get_invites(client):
if "@labelbox.com" in invite.email:
cancel_invite(client, invite.uid)


@pytest.fixture
def configured_project_with_label(client, rand_gen, image_url, project, dataset,
data_row, wait_for_label_processing):
"""Project with a connected dataset, having one datarow
Project contains an ontology with 1 bbox tool
Additionally includes a create_label method for any needed extra labels
One label is already created and yielded when using fixture
"""
project._wait_until_data_rows_are_processed(
data_row_ids=[data_row.uid],
wait_processing_max_seconds=DATA_ROW_PROCESSING_WAIT_TIMEOUT_SECONDS,
sleep_interval=DATA_ROW_PROCESSING_WAIT_SLEEP_INTERNAL_SECONDS)

project.create_batch(
rand_gen(str),
[data_row.uid], # sample of data row objects
5 # priority between 1(Highest) - 5(lowest)
)
ontology = _setup_ontology(project)
label = _create_label(project, data_row, ontology,
wait_for_label_processing)
yield [project, dataset, data_row, label]

for label in project.labels():
label.delete()


def _create_label(project, data_row, ontology, wait_for_label_processing):
predictions = [{
"uuid": str(uuid.uuid4()),
"schemaId": ontology.tools[0].feature_schema_id,
"dataRow": {
"id": data_row.uid
},
"bbox": {
"top": 20,
"left": 20,
"height": 50,
"width": 50
}
}]

def create_label():
""" Ad-hoc function to create a LabelImport
Creates a LabelImport task which will create a label
"""
upload_task = LabelImport.create_from_objects(
project.client, project.uid, f'label-import-{uuid.uuid4()}',
predictions)
upload_task.wait_until_done(sleep_time_seconds=5)
assert upload_task.state == AnnotationImportState.FINISHED, "Label Import did not finish"
assert len(
upload_task.errors
) == 0, f"Label Import {upload_task.name} failed with errors {upload_task.errors}"

project.create_label = create_label
project.create_label()
label = wait_for_label_processing(project)[0]
return label


def _setup_ontology(project):
editor = list(
project.client.get_labeling_frontends(
where=LabelingFrontend.name == "editor"))[0]
ontology_builder = OntologyBuilder(tools=[
Tool(tool=Tool.Type.BBOX, name="test-bbox-class"),
])
project.setup(editor, ontology_builder.asdict())
# TODO: ontology may not be synchronous after setup. remove sleep when api is more consistent
time.sleep(2)
return OntologyBuilder.from_project(project)

0 comments on commit 3ca3781

Please sign in to comment.