From 98849ffbda641200f301b63455d09dfbc19f3dbd Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 17 May 2024 09:42:59 -0500 Subject: [PATCH 01/10] fixes some test --- libs/labelbox/tests/conftest.py | 5 ++++- libs/labelbox/tests/integration/conftest.py | 5 ++++- libs/labelbox/tests/integration/test_project.py | 8 +++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/labelbox/tests/conftest.py b/libs/labelbox/tests/conftest.py index a5a0d0f1f..780ef30a2 100644 --- a/libs/labelbox/tests/conftest.py +++ b/libs/labelbox/tests/conftest.py @@ -929,7 +929,10 @@ def export_v2_test_helpers() -> Type[ExportV2Helpers]: @pytest.fixture def big_dataset_data_row_ids(big_dataset: Dataset): - yield [dr.uid for dr in list(big_dataset.export_data_rows())] + export_task = big_dataset.export() + export_task.wait_till_done() + stream = export_task.get_stream() + yield [dr.json_str["data_row"]["id"] for dr in stream] @pytest.fixture(scope='function') diff --git a/libs/labelbox/tests/integration/conftest.py b/libs/labelbox/tests/integration/conftest.py index 7a1d2d8cc..aa4d3f7f5 100644 --- a/libs/labelbox/tests/integration/conftest.py +++ b/libs/labelbox/tests/integration/conftest.py @@ -314,7 +314,10 @@ def export_v2_test_helpers() -> Type[ExportV2Helpers]: @pytest.fixture def big_dataset_data_row_ids(big_dataset: Dataset): - yield [dr.uid for dr in list(big_dataset.export_data_rows())] + export_task = big_dataset.export() + export_task.wait_till_done() + stream = export_task.get_stream() + yield [dr.json_str["data_row"]["id"] for dr in stream] @pytest.fixture(scope='function') diff --git a/libs/labelbox/tests/integration/test_project.py b/libs/labelbox/tests/integration/test_project.py index 85d67a251..f96f419ca 100644 --- a/libs/labelbox/tests/integration/test_project.py +++ b/libs/labelbox/tests/integration/test_project.py @@ -5,7 +5,7 @@ import pytest import requests -from labelbox import Project, LabelingFrontend, Dataset +from labelbox import Project, LabelingFrontend, Dataset, DataRow from labelbox.exceptions import InvalidQueryError from labelbox.schema.media_type import MediaType from labelbox.schema.quality_mode import QualityMode @@ -201,8 +201,10 @@ def test_batches(project: Project, dataset: Dataset, image_url): }, ] * 2) task.wait_till_done() - # TODO: Move to export_v2 - data_rows = [dr.uid for dr in list(dataset.export_data_rows())] + export_task = dataset.export() + export_task.wait_till_done() + stream = export_task.get_stream() + data_rows = [dr.json_str["data_row"]["id"] for dr in stream] batch_one = f'batch one {uuid.uuid4()}' batch_two = f'batch two {uuid.uuid4()}' project.create_batch(batch_one, [data_rows[0]]) From 8168cb829de3fb3341368a3bd92bfe007aa3f230 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 17 May 2024 10:02:01 -0500 Subject: [PATCH 02/10] switched default streamable convertor --- libs/labelbox/src/labelbox/schema/export_task.py | 2 +- libs/labelbox/tests/conftest.py | 5 +++-- libs/labelbox/tests/integration/test_batch.py | 10 ++++++++-- libs/labelbox/tests/integration/test_project.py | 7 ++++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/export_task.py b/libs/labelbox/src/labelbox/schema/export_task.py index 473333d1f..5236dd182 100644 --- a/libs/labelbox/src/labelbox/schema/export_task.py +++ b/libs/labelbox/src/labelbox/schema/export_task.py @@ -896,7 +896,7 @@ def get_stream( "get_stream is deprecated and will be removed in a future release, use get_buffered_stream" ) if converter is None: - converter = JsonConverter() + converter = BufferedJsonConverterOutput() """Returns the result of the task.""" if self._task.status == "FAILED": raise ExportTask.ExportTaskException("Task failed") diff --git a/libs/labelbox/tests/conftest.py b/libs/labelbox/tests/conftest.py index 780ef30a2..0432cb1ce 100644 --- a/libs/labelbox/tests/conftest.py +++ b/libs/labelbox/tests/conftest.py @@ -28,6 +28,7 @@ from labelbox import OntologyBuilder, Tool, Option, Classification, MediaType from labelbox.orm import query from labelbox.pagination import PaginatedCollection +from labelbox.schema.export_task import BufferedJsonConverterOutput from labelbox.schema.annotation_import import LabelImport from labelbox.schema.catalog import Catalog from labelbox.schema.enums import AnnotationImportState @@ -931,8 +932,8 @@ def export_v2_test_helpers() -> Type[ExportV2Helpers]: def big_dataset_data_row_ids(big_dataset: Dataset): export_task = big_dataset.export() export_task.wait_till_done() - stream = export_task.get_stream() - yield [dr.json_str["data_row"]["id"] for dr in stream] + stream = export_task.get_stream(converter=BufferedJsonConverterOutput) + yield [dr.json["data_row"]["id"] for dr in stream] @pytest.fixture(scope='function') diff --git a/libs/labelbox/tests/integration/test_batch.py b/libs/labelbox/tests/integration/test_batch.py index b7d6875f9..b07fefb4c 100644 --- a/libs/labelbox/tests/integration/test_batch.py +++ b/libs/labelbox/tests/integration/test_batch.py @@ -92,7 +92,10 @@ def test_create_batch_async(project: Project, def test_create_batch_with_consensus_settings(project: Project, small_dataset: Dataset): - data_rows = [dr.uid for dr in list(small_dataset.export_data_rows())] + export_task = small_dataset.export() + export_task.wait_till_done() + stream = export_task.get_stream() + data_rows = [dr.json_str["data_row"]["id"] for dr in stream] consensus_settings = {"coverage_percentage": 0.1, "number_of_labels": 3} batch = project.create_batch("batch with consensus settings", data_rows, @@ -112,7 +115,10 @@ def test_create_batch_with_data_row_class(project: Project, def test_archive_batch(project: Project, small_dataset: Dataset): - data_rows = [dr.uid for dr in list(small_dataset.export_data_rows())] + export_task = small_dataset.export() + export_task.wait_till_done() + stream = export_task.get_stream() + data_rows = [dr.json_str["data_row"]["id"] for dr in stream] batch = project.create_batch("batch to archive", data_rows) batch.remove_queued_data_rows() exported_data_rows = list(batch.export_data_rows()) diff --git a/libs/labelbox/tests/integration/test_project.py b/libs/labelbox/tests/integration/test_project.py index f96f419ca..600871791 100644 --- a/libs/labelbox/tests/integration/test_project.py +++ b/libs/labelbox/tests/integration/test_project.py @@ -5,11 +5,12 @@ import pytest import requests -from labelbox import Project, LabelingFrontend, Dataset, DataRow +from labelbox import Project, LabelingFrontend, Dataset from labelbox.exceptions import InvalidQueryError from labelbox.schema.media_type import MediaType from labelbox.schema.quality_mode import QualityMode from labelbox.schema.queue_mode import QueueMode +from labelbox.schema.export_task import BufferedJsonConverterOutput def test_project(client, rand_gen): @@ -203,8 +204,8 @@ def test_batches(project: Project, dataset: Dataset, image_url): task.wait_till_done() export_task = dataset.export() export_task.wait_till_done() - stream = export_task.get_stream() - data_rows = [dr.json_str["data_row"]["id"] for dr in stream] + stream = export_task.get_stream(converter=BufferedJsonConverterOutput) + data_rows = [dr.json["data_row"]["id"] for dr in stream] batch_one = f'batch one {uuid.uuid4()}' batch_two = f'batch two {uuid.uuid4()}' project.create_batch(batch_one, [data_rows[0]]) From 9527d83a8620fcbe3a97412c08696dc50d2cd83b Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 17 May 2024 10:04:28 -0500 Subject: [PATCH 03/10] modified BufferedTask --- libs/labelbox/src/labelbox/schema/export_task.py | 2 +- libs/labelbox/tests/conftest.py | 2 +- libs/labelbox/tests/integration/test_project.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/export_task.py b/libs/labelbox/src/labelbox/schema/export_task.py index 5236dd182..3ac114506 100644 --- a/libs/labelbox/src/labelbox/schema/export_task.py +++ b/libs/labelbox/src/labelbox/schema/export_task.py @@ -896,7 +896,7 @@ def get_stream( "get_stream is deprecated and will be removed in a future release, use get_buffered_stream" ) if converter is None: - converter = BufferedJsonConverterOutput() + converter = BufferedJsonConverterOutput """Returns the result of the task.""" if self._task.status == "FAILED": raise ExportTask.ExportTaskException("Task failed") diff --git a/libs/labelbox/tests/conftest.py b/libs/labelbox/tests/conftest.py index 0432cb1ce..bed0e624b 100644 --- a/libs/labelbox/tests/conftest.py +++ b/libs/labelbox/tests/conftest.py @@ -932,7 +932,7 @@ def export_v2_test_helpers() -> Type[ExportV2Helpers]: def big_dataset_data_row_ids(big_dataset: Dataset): export_task = big_dataset.export() export_task.wait_till_done() - stream = export_task.get_stream(converter=BufferedJsonConverterOutput) + stream = export_task.get_stream() yield [dr.json["data_row"]["id"] for dr in stream] diff --git a/libs/labelbox/tests/integration/test_project.py b/libs/labelbox/tests/integration/test_project.py index 600871791..a40d630f4 100644 --- a/libs/labelbox/tests/integration/test_project.py +++ b/libs/labelbox/tests/integration/test_project.py @@ -204,7 +204,7 @@ def test_batches(project: Project, dataset: Dataset, image_url): task.wait_till_done() export_task = dataset.export() export_task.wait_till_done() - stream = export_task.get_stream(converter=BufferedJsonConverterOutput) + stream = export_task.get_stream() data_rows = [dr.json["data_row"]["id"] for dr in stream] batch_one = f'batch one {uuid.uuid4()}' batch_two = f'batch two {uuid.uuid4()}' From 70b7d8f5c144bb869cc9b3152dc44e9db8639ee9 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 17 May 2024 10:32:52 -0500 Subject: [PATCH 04/10] changed default convertor --- libs/labelbox/src/labelbox/schema/export_task.py | 4 ++-- libs/labelbox/tests/integration/test_batch.py | 10 ++++++++-- libs/labelbox/tests/integration/test_project.py | 1 - 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/export_task.py b/libs/labelbox/src/labelbox/schema/export_task.py index 3ac114506..11786b21b 100644 --- a/libs/labelbox/src/labelbox/schema/export_task.py +++ b/libs/labelbox/src/labelbox/schema/export_task.py @@ -896,7 +896,7 @@ def get_stream( "get_stream is deprecated and will be removed in a future release, use get_buffered_stream" ) if converter is None: - converter = BufferedJsonConverterOutput + converter = _BufferedJsonConverter() """Returns the result of the task.""" if self._task.status == "FAILED": raise ExportTask.ExportTaskException("Task failed") @@ -919,4 +919,4 @@ def get_stream( @staticmethod def get_task(client, task_id): """Returns the task with the given id.""" - return ExportTask(Task.get_task(client, task_id)) + return ExportTask(Task.get_task(client, task_id)) \ No newline at end of file diff --git a/libs/labelbox/tests/integration/test_batch.py b/libs/labelbox/tests/integration/test_batch.py index b07fefb4c..c4f69ddc7 100644 --- a/libs/labelbox/tests/integration/test_batch.py +++ b/libs/labelbox/tests/integration/test_batch.py @@ -120,9 +120,15 @@ def test_archive_batch(project: Project, small_dataset: Dataset): stream = export_task.get_stream() data_rows = [dr.json_str["data_row"]["id"] for dr in stream] batch = project.create_batch("batch to archive", data_rows) + batch.remove_queued_data_rows() - exported_data_rows = list(batch.export_data_rows()) - + + export_params = {"batch_ids": [batch.uid]} + export_task = project.export(params=export_params) + export_task.wait_till_done() + stream = export_task.get_stream() + exported_data_rows = [dr for dr in stream] + assert len(exported_data_rows) == 0 diff --git a/libs/labelbox/tests/integration/test_project.py b/libs/labelbox/tests/integration/test_project.py index a40d630f4..9e0981330 100644 --- a/libs/labelbox/tests/integration/test_project.py +++ b/libs/labelbox/tests/integration/test_project.py @@ -10,7 +10,6 @@ from labelbox.schema.media_type import MediaType from labelbox.schema.quality_mode import QualityMode from labelbox.schema.queue_mode import QueueMode -from labelbox.schema.export_task import BufferedJsonConverterOutput def test_project(client, rand_gen): From 7b9cdaca5e91d0d6e66d7738ed2f2c059c0174d9 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Fri, 17 May 2024 10:43:17 -0500 Subject: [PATCH 05/10] switched to new buffered json convertor --- .../src/labelbox/schema/export_task.py | 2 +- libs/labelbox/tests/conftest.py | 4 +- .../test_send_to_annotate_mea.py | 2 +- libs/labelbox/tests/integration/conftest.py | 17 ++++- libs/labelbox/tests/integration/test_batch.py | 68 ++++++++++++------- .../tests/integration/test_batches.py | 5 +- .../tests/integration/test_project.py | 34 ++++++---- .../integration/test_send_to_annotate.py | 17 +++-- libs/labelbox/tests/integration/test_task.py | 3 +- 9 files changed, 102 insertions(+), 50 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/export_task.py b/libs/labelbox/src/labelbox/schema/export_task.py index 11786b21b..8f87318f2 100644 --- a/libs/labelbox/src/labelbox/schema/export_task.py +++ b/libs/labelbox/src/labelbox/schema/export_task.py @@ -896,7 +896,7 @@ def get_stream( "get_stream is deprecated and will be removed in a future release, use get_buffered_stream" ) if converter is None: - converter = _BufferedJsonConverter() + converter = JsonConverter() """Returns the result of the task.""" if self._task.status == "FAILED": raise ExportTask.ExportTaskException("Task failed") diff --git a/libs/labelbox/tests/conftest.py b/libs/labelbox/tests/conftest.py index bed0e624b..1a763a94a 100644 --- a/libs/labelbox/tests/conftest.py +++ b/libs/labelbox/tests/conftest.py @@ -13,6 +13,7 @@ from typing import Type from enum import Enum from typing import Tuple +import json from labelbox import Dataset, DataRow from labelbox import MediaType @@ -28,7 +29,6 @@ from labelbox import OntologyBuilder, Tool, Option, Classification, MediaType from labelbox.orm import query from labelbox.pagination import PaginatedCollection -from labelbox.schema.export_task import BufferedJsonConverterOutput from labelbox.schema.annotation_import import LabelImport from labelbox.schema.catalog import Catalog from labelbox.schema.enums import AnnotationImportState @@ -933,7 +933,7 @@ def big_dataset_data_row_ids(big_dataset: Dataset): export_task = big_dataset.export() export_task.wait_till_done() stream = export_task.get_stream() - yield [dr.json["data_row"]["id"] for dr in stream] + yield [json.loads(dr.json_str)["data_row"]["id"] for dr in stream] @pytest.fixture(scope='function') diff --git a/libs/labelbox/tests/data/annotation_import/test_send_to_annotate_mea.py b/libs/labelbox/tests/data/annotation_import/test_send_to_annotate_mea.py index 9e12131c5..6727e84b0 100644 --- a/libs/labelbox/tests/data/annotation_import/test_send_to_annotate_mea.py +++ b/libs/labelbox/tests/data/annotation_import/test_send_to_annotate_mea.py @@ -55,7 +55,7 @@ def test_send_to_annotate_from_model(client, configured_project, # Check that the data row was sent to the new project destination_batches = list(destination_project.batches()) assert len(destination_batches) == 1 - + destination_data_rows = list(destination_batches[0].export_data_rows()) assert len(destination_data_rows) == len(data_row_ids) assert all([dr.uid in data_row_ids for dr in destination_data_rows]) diff --git a/libs/labelbox/tests/integration/conftest.py b/libs/labelbox/tests/integration/conftest.py index aa4d3f7f5..9356f1918 100644 --- a/libs/labelbox/tests/integration/conftest.py +++ b/libs/labelbox/tests/integration/conftest.py @@ -95,6 +95,21 @@ def configured_project(project_with_empty_ontology, initial_dataset, rand_gen, batch.delete() +@pytest.fixture +def configured_project_with_basic_ontology(client, rand_gen): + ontology_builder = OntologyBuilder(tools=[Tool(tool=Tool.Type.BBOX, name="Box 1", color="#ff0000")]) + project = client.create_project(name=rand_gen(str), + queue_mode=QueueMode.Batch, + media_type=MediaType.Image) + ontology = client.create_ontology('Integration Test Ontology', + ontology_builder.asdict(), + MediaType.Image) + project.setup_editor(ontology) + + yield project + project.delete() + client.delete_unused_ontology(ontology.uid) + @pytest.fixture def configured_project_with_complex_ontology(client, initial_dataset, rand_gen, @@ -317,7 +332,7 @@ def big_dataset_data_row_ids(big_dataset: Dataset): export_task = big_dataset.export() export_task.wait_till_done() stream = export_task.get_stream() - yield [dr.json_str["data_row"]["id"] for dr in stream] + yield [json.loads(dr.json_str)["data_row"]["id"] for dr in stream] @pytest.fixture(scope='function') diff --git a/libs/labelbox/tests/integration/test_batch.py b/libs/labelbox/tests/integration/test_batch.py index c4f69ddc7..f4d11ed94 100644 --- a/libs/labelbox/tests/integration/test_batch.py +++ b/libs/labelbox/tests/integration/test_batch.py @@ -1,10 +1,10 @@ import time from typing import List from uuid import uuid4 - +import json import pytest -from labelbox import Dataset, Project +from labelbox import Dataset, Project, Ontology from labelbox.exceptions import ProcessingWaitTimeout, MalformedQueryException, ResourceConflict, LabelboxError @@ -94,8 +94,8 @@ def test_create_batch_with_consensus_settings(project: Project, small_dataset: Dataset): export_task = small_dataset.export() export_task.wait_till_done() - stream = export_task.get_stream() - data_rows = [dr.json_str["data_row"]["id"] for dr in stream] + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] consensus_settings = {"coverage_percentage": 0.1, "number_of_labels": 3} batch = project.create_batch("batch with consensus settings", data_rows, @@ -108,32 +108,35 @@ def test_create_batch_with_consensus_settings(project: Project, def test_create_batch_with_data_row_class(project: Project, small_dataset: Dataset): - data_rows = list(small_dataset.export_data_rows()) + export_task = small_dataset.export() + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] batch = project.create_batch("test-batch-data-rows", data_rows, 3) assert batch.name == "test-batch-data-rows" assert batch.size == len(data_rows) - -def test_archive_batch(project: Project, small_dataset: Dataset): +def test_archive_batch(configured_project_with_basic_ontology: Project, small_dataset: Dataset): export_task = small_dataset.export() export_task.wait_till_done() - stream = export_task.get_stream() - data_rows = [dr.json_str["data_row"]["id"] for dr in stream] - batch = project.create_batch("batch to archive", data_rows) - + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] + batch = configured_project_with_basic_ontology.create_batch("batch to archive", data_rows) batch.remove_queued_data_rows() - export_params = {"batch_ids": [batch.uid]} - export_task = project.export(params=export_params) + export_task = configured_project_with_basic_ontology.export(filters={"batch_ids": [batch.uid]}) export_task.wait_till_done() - stream = export_task.get_stream() + stream = export_task.get_buffered_stream() exported_data_rows = [dr for dr in stream] - + print(exported_data_rows) assert len(exported_data_rows) == 0 def test_delete(project: Project, small_dataset: Dataset): - data_rows = [dr.uid for dr in list(small_dataset.export_data_rows())] + export_task = small_dataset.export() + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] batch = project.create_batch("batch to delete", data_rows) batch.delete() @@ -141,7 +144,10 @@ def test_delete(project: Project, small_dataset: Dataset): def test_batch_project(project: Project, small_dataset: Dataset): - data_rows = [dr.uid for dr in list(small_dataset.export_data_rows())] + export_task = small_dataset.export() + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] batch = project.create_batch("batch to test project relationship", data_rows) @@ -197,9 +203,9 @@ def test_batch_creation_with_processing_timeout( project.create_batch("batch to test failed data rows", data_row_ids) project._wait_processing_max_seconds = stashed_wait_timeout - +@pytest.mark.export_v1("export_v1 test remove later") def test_export_data_rows(project: Project, dataset: Dataset, image_url: str, - external_id: str): + external_id: str , ontology: Ontology): n_data_rows = 2 task = dataset.create_data_rows([ { @@ -267,7 +273,10 @@ def test_list_project_batches_with_no_batches(project: Project): reason="Test cannot be used effectively with MAL/LabelImport. \ Fix/Unskip after resolving deletion with MAL/LabelImport") def test_delete_labels(project, small_dataset): - data_rows = [dr.uid for dr in list(small_dataset.export_data_rows())] + export_task = small_dataset.export() + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] batch = project.create_batch("batch to delete labels", data_rows) @@ -275,10 +284,23 @@ def test_delete_labels(project, small_dataset): reason="Test cannot be used effectively with MAL/LabelImport. \ Fix/Unskip after resolving deletion with MAL/LabelImport") def test_delete_labels_with_templates(project: Project, small_dataset: Dataset): - data_rows = [dr.uid for dr in list(small_dataset.export_data_rows())] + export_task = small_dataset.export() + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] batch = project.create_batch("batch to delete labels w templates", data_rows) - exported_data_rows = list(batch.export_data_rows()) + + export_task = project.export(filters={"batch_ids": [batch.uid]}) + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + exported_data_rows = [dr.json["data_row"]["id"] for dr in stream] + res = batch.delete_labels(labels_as_template=True) - exported_data_rows = list(batch.export_data_rows()) + + export_task = project.export(filters={"batch_ids": [batch.uid]}) + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + exported_data_rows = [dr.json["data_row"]["id"] for dr in stream] + assert len(exported_data_rows) == 5 diff --git a/libs/labelbox/tests/integration/test_batches.py b/libs/labelbox/tests/integration/test_batches.py index 12a4a4355..5c24a65f0 100644 --- a/libs/labelbox/tests/integration/test_batches.py +++ b/libs/labelbox/tests/integration/test_batches.py @@ -20,7 +20,10 @@ def test_create_batches(project: Project, big_dataset_data_row_ids: List[str]): def test_create_batches_from_dataset(project: Project, big_dataset: Dataset): - data_rows = [dr.uid for dr in list(big_dataset.export_data_rows())] + export_task = big_dataset.export() + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + data_rows = [dr.json["data_row"]["id"] for dr in stream] project._wait_until_data_rows_are_processed(data_rows, [], 300) task = project.create_batches_from_dataset("test-batch", diff --git a/libs/labelbox/tests/integration/test_project.py b/libs/labelbox/tests/integration/test_project.py index 9e0981330..d61ab8b0f 100644 --- a/libs/labelbox/tests/integration/test_project.py +++ b/libs/labelbox/tests/integration/test_project.py @@ -1,11 +1,10 @@ import time import os import uuid - import pytest import requests -from labelbox import Project, LabelingFrontend, Dataset +from labelbox import Project, LabelingFrontend, Dataset, StreamType from labelbox.exceptions import InvalidQueryError from labelbox.schema.media_type import MediaType from labelbox.schema.quality_mode import QualityMode @@ -203,7 +202,7 @@ def test_batches(project: Project, dataset: Dataset, image_url): task.wait_till_done() export_task = dataset.export() export_task.wait_till_done() - stream = export_task.get_stream() + stream = export_task.get_buffered_stream() data_rows = [dr.json["data_row"]["id"] for dr in stream] batch_one = f'batch one {uuid.uuid4()}' batch_two = f'batch two {uuid.uuid4()}' @@ -215,23 +214,32 @@ def test_batches(project: Project, dataset: Dataset, image_url): @pytest.mark.parametrize('data_rows', [2], indirect=True) -def test_create_batch_with_global_keys_sync(project: Project, data_rows): +def test_create_batch_with_global_keys_sync(configured_project_with_basic_ontology: Project, data_rows): global_keys = [dr.global_key for dr in data_rows] batch_name = f'batch {uuid.uuid4()}' - batch = project.create_batch(batch_name, global_keys=global_keys) - # TODO: Move to export_v2 - batch_data_rows = set(batch.export_data_rows()) - assert batch_data_rows == set(data_rows) + batch = configured_project_with_basic_ontology.create_batch(batch_name, global_keys=global_keys) + + export_task = configured_project_with_basic_ontology.export(filters={"batch_ids": [batch.uid]}) + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + + batch_data_rows_global_keys = [dr.json["data_row"]["global_key"] for dr in stream] + assert batch_data_rows_global_keys == global_keys @pytest.mark.parametrize('data_rows', [2], indirect=True) -def test_create_batch_with_global_keys_async(project: Project, data_rows): +def test_create_batch_with_global_keys_async(configured_project_with_basic_ontology: Project, data_rows): global_keys = [dr.global_key for dr in data_rows] batch_name = f'batch {uuid.uuid4()}' - batch = project._create_batch_async(batch_name, global_keys=global_keys) - # TODO: Move to export_v2 - batch_data_rows = set(batch.export_data_rows()) - assert batch_data_rows == set(data_rows) + batch = configured_project_with_basic_ontology._create_batch_async(batch_name, global_keys=global_keys) + + export_task = configured_project_with_basic_ontology.export(filters={"batch_ids": [batch.uid]}) + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + + batch_data_rows_global_keys = [dr.json["data_row"]["global_key"] for dr in stream] + + assert batch_data_rows_global_keys == global_keys def test_media_type(client, project: Project, rand_gen): diff --git a/libs/labelbox/tests/integration/test_send_to_annotate.py b/libs/labelbox/tests/integration/test_send_to_annotate.py index 631d8aec6..01844c95b 100644 --- a/libs/labelbox/tests/integration/test_send_to_annotate.py +++ b/libs/labelbox/tests/integration/test_send_to_annotate.py @@ -1,11 +1,12 @@ -from labelbox import UniqueIds, OntologyBuilder, LabelingFrontend +from labelbox import UniqueIds, OntologyBuilder, LabelingFrontend, Project, Ontology, Client from labelbox.schema.conflict_resolution_strategy import ConflictResolutionStrategy +from typing import List def test_send_to_annotate_include_annotations( - client, configured_batch_project_with_label, project_pack, ontology): + client: Client, configured_batch_project_with_label: Project, project_pack: List[Project], ontology: Ontology): [source_project, _, data_row, _] = configured_batch_project_with_label - destination_project = project_pack[0] + destination_project: Project = project_pack[0] src_ontology = source_project.ontology() destination_project.setup_editor(ontology) @@ -45,10 +46,14 @@ def test_send_to_annotate_include_annotations( # Check that the data row was sent to the new project destination_batches = list(destination_project.batches()) assert len(destination_batches) == 1 - - destination_data_rows = list(destination_batches[0].export_data_rows()) + + export_task = destination_project.export(filters={"batch_ids": [destination_batches[0].uid]}) + export_task.wait_till_done() + stream = export_task.get_buffered_stream() + + destination_data_rows = [dr.json["data_row"]["id"] for dr in stream] assert len(destination_data_rows) == 1 - assert destination_data_rows[0].uid == data_row.uid + assert destination_data_rows[0] == data_row.uid # Verify annotations were copied into the destination project destination_project_labels = (list(destination_project.labels())) diff --git a/libs/labelbox/tests/integration/test_task.py b/libs/labelbox/tests/integration/test_task.py index aaa8c491e..66b34d456 100644 --- a/libs/labelbox/tests/integration/test_task.py +++ b/libs/labelbox/tests/integration/test_task.py @@ -58,10 +58,9 @@ def test_task_success_json(dataset, image_url, snapshot): 'test_task.test_task_success_json.json') assert len(task.result) - +@pytest.mark.export_v1("export_v1 test remove later") def test_task_success_label_export(client, configured_project_with_label): project, _, _, _ = configured_project_with_label - # TODO: Move to export_v2 project.export_labels() user = client.get_user() task = None From 81310cd6443624c8c802c66785d5724f39c8c9a9 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Tue, 28 May 2024 22:15:04 -0500 Subject: [PATCH 06/10] fixed integration --- libs/labelbox/tests/integration/test_batch.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libs/labelbox/tests/integration/test_batch.py b/libs/labelbox/tests/integration/test_batch.py index f4d11ed94..96b9ce135 100644 --- a/libs/labelbox/tests/integration/test_batch.py +++ b/libs/labelbox/tests/integration/test_batch.py @@ -1,7 +1,6 @@ import time from typing import List from uuid import uuid4 -import json import pytest from labelbox import Dataset, Project, Ontology @@ -116,16 +115,20 @@ def test_create_batch_with_data_row_class(project: Project, assert batch.name == "test-batch-data-rows" assert batch.size == len(data_rows) -def test_archive_batch(configured_project_with_basic_ontology: Project, small_dataset: Dataset): + +def test_archive_batch(configured_project_with_basic_ontology: Project, + small_dataset: Dataset): export_task = small_dataset.export() export_task.wait_till_done() stream = export_task.get_buffered_stream() data_rows = [dr.json["data_row"]["id"] for dr in stream] - batch = configured_project_with_basic_ontology.create_batch("batch to archive", data_rows) + batch = configured_project_with_basic_ontology.create_batch( + "batch to archive", data_rows) batch.remove_queued_data_rows() - - export_task = configured_project_with_basic_ontology.export(filters={"batch_ids": [batch.uid]}) - export_task.wait_till_done() + + export_task = configured_project_with_basic_ontology.export( + filters={"batch_ids": [batch.uid]}) + export_task.wait_till_done() stream = export_task.get_buffered_stream() exported_data_rows = [dr for dr in stream] print(exported_data_rows) @@ -203,9 +206,10 @@ def test_batch_creation_with_processing_timeout( project.create_batch("batch to test failed data rows", data_row_ids) project._wait_processing_max_seconds = stashed_wait_timeout + @pytest.mark.export_v1("export_v1 test remove later") def test_export_data_rows(project: Project, dataset: Dataset, image_url: str, - external_id: str , ontology: Ontology): + external_id: str, ontology: Ontology): n_data_rows = 2 task = dataset.create_data_rows([ { @@ -290,14 +294,14 @@ def test_delete_labels_with_templates(project: Project, small_dataset: Dataset): data_rows = [dr.json["data_row"]["id"] for dr in stream] batch = project.create_batch("batch to delete labels w templates", data_rows) - + export_task = project.export(filters={"batch_ids": [batch.uid]}) export_task.wait_till_done() stream = export_task.get_buffered_stream() exported_data_rows = [dr.json["data_row"]["id"] for dr in stream] res = batch.delete_labels(labels_as_template=True) - + export_task = project.export(filters={"batch_ids": [batch.uid]}) export_task.wait_till_done() stream = export_task.get_buffered_stream() From 46832656fb95b1ea08dd7a8471af2e94f1837514 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 07:53:33 -0500 Subject: [PATCH 07/10] finsihed --- libs/labelbox/tests/conftest.py | 5 ++-- libs/labelbox/tests/integration/conftest.py | 15 ----------- libs/labelbox/tests/integration/test_batch.py | 22 ++++++---------- .../tests/integration/test_project.py | 25 ++++++------------- 4 files changed, 17 insertions(+), 50 deletions(-) diff --git a/libs/labelbox/tests/conftest.py b/libs/labelbox/tests/conftest.py index 1a763a94a..80229e319 100644 --- a/libs/labelbox/tests/conftest.py +++ b/libs/labelbox/tests/conftest.py @@ -13,7 +13,6 @@ from typing import Type from enum import Enum from typing import Tuple -import json from labelbox import Dataset, DataRow from labelbox import MediaType @@ -932,8 +931,8 @@ def export_v2_test_helpers() -> Type[ExportV2Helpers]: def big_dataset_data_row_ids(big_dataset: Dataset): export_task = big_dataset.export() export_task.wait_till_done() - stream = export_task.get_stream() - yield [json.loads(dr.json_str)["data_row"]["id"] for dr in stream] + stream = export_task.get_buffered_stream() + yield [dr.json["data_row"]["id"] for dr in stream] @pytest.fixture(scope='function') diff --git a/libs/labelbox/tests/integration/conftest.py b/libs/labelbox/tests/integration/conftest.py index 9356f1918..610573686 100644 --- a/libs/labelbox/tests/integration/conftest.py +++ b/libs/labelbox/tests/integration/conftest.py @@ -95,21 +95,6 @@ def configured_project(project_with_empty_ontology, initial_dataset, rand_gen, batch.delete() -@pytest.fixture -def configured_project_with_basic_ontology(client, rand_gen): - ontology_builder = OntologyBuilder(tools=[Tool(tool=Tool.Type.BBOX, name="Box 1", color="#ff0000")]) - project = client.create_project(name=rand_gen(str), - queue_mode=QueueMode.Batch, - media_type=MediaType.Image) - ontology = client.create_ontology('Integration Test Ontology', - ontology_builder.asdict(), - MediaType.Image) - project.setup_editor(ontology) - - yield project - project.delete() - client.delete_unused_ontology(ontology.uid) - @pytest.fixture def configured_project_with_complex_ontology(client, initial_dataset, rand_gen, diff --git a/libs/labelbox/tests/integration/test_batch.py b/libs/labelbox/tests/integration/test_batch.py index 96b9ce135..d5e3b7a0f 100644 --- a/libs/labelbox/tests/integration/test_batch.py +++ b/libs/labelbox/tests/integration/test_batch.py @@ -3,7 +3,7 @@ from uuid import uuid4 import pytest -from labelbox import Dataset, Project, Ontology +from labelbox import Dataset, Project from labelbox.exceptions import ProcessingWaitTimeout, MalformedQueryException, ResourceConflict, LabelboxError @@ -116,23 +116,17 @@ def test_create_batch_with_data_row_class(project: Project, assert batch.size == len(data_rows) -def test_archive_batch(configured_project_with_basic_ontology: Project, - small_dataset: Dataset): +def test_archive_batch(project: Project, small_dataset: Dataset): export_task = small_dataset.export() export_task.wait_till_done() stream = export_task.get_buffered_stream() data_rows = [dr.json["data_row"]["id"] for dr in stream] - batch = configured_project_with_basic_ontology.create_batch( - "batch to archive", data_rows) + + batch = project.create_batch("batch to archive", data_rows) batch.remove_queued_data_rows() - - export_task = configured_project_with_basic_ontology.export( - filters={"batch_ids": [batch.uid]}) - export_task.wait_till_done() - stream = export_task.get_buffered_stream() - exported_data_rows = [dr for dr in stream] - print(exported_data_rows) - assert len(exported_data_rows) == 0 + overview = project.get_overview() + + assert overview.to_label == 0 def test_delete(project: Project, small_dataset: Dataset): @@ -209,7 +203,7 @@ def test_batch_creation_with_processing_timeout( @pytest.mark.export_v1("export_v1 test remove later") def test_export_data_rows(project: Project, dataset: Dataset, image_url: str, - external_id: str, ontology: Ontology): + external_id: str): n_data_rows = 2 task = dataset.create_data_rows([ { diff --git a/libs/labelbox/tests/integration/test_project.py b/libs/labelbox/tests/integration/test_project.py index d61ab8b0f..9343314cb 100644 --- a/libs/labelbox/tests/integration/test_project.py +++ b/libs/labelbox/tests/integration/test_project.py @@ -4,7 +4,7 @@ import pytest import requests -from labelbox import Project, LabelingFrontend, Dataset, StreamType +from labelbox import Project, LabelingFrontend, Dataset from labelbox.exceptions import InvalidQueryError from labelbox.schema.media_type import MediaType from labelbox.schema.quality_mode import QualityMode @@ -214,32 +214,21 @@ def test_batches(project: Project, dataset: Dataset, image_url): @pytest.mark.parametrize('data_rows', [2], indirect=True) -def test_create_batch_with_global_keys_sync(configured_project_with_basic_ontology: Project, data_rows): +def test_create_batch_with_global_keys_sync(project: Project, data_rows): global_keys = [dr.global_key for dr in data_rows] batch_name = f'batch {uuid.uuid4()}' - batch = configured_project_with_basic_ontology.create_batch(batch_name, global_keys=global_keys) + batch = project.create_batch(batch_name, global_keys=global_keys) - export_task = configured_project_with_basic_ontology.export(filters={"batch_ids": [batch.uid]}) - export_task.wait_till_done() - stream = export_task.get_buffered_stream() - - batch_data_rows_global_keys = [dr.json["data_row"]["global_key"] for dr in stream] - assert batch_data_rows_global_keys == global_keys + assert batch.size == len(set(data_rows)) @pytest.mark.parametrize('data_rows', [2], indirect=True) -def test_create_batch_with_global_keys_async(configured_project_with_basic_ontology: Project, data_rows): +def test_create_batch_with_global_keys_async(project: Project, data_rows): global_keys = [dr.global_key for dr in data_rows] batch_name = f'batch {uuid.uuid4()}' - batch = configured_project_with_basic_ontology._create_batch_async(batch_name, global_keys=global_keys) + batch = project._create_batch_async(batch_name, global_keys=global_keys) - export_task = configured_project_with_basic_ontology.export(filters={"batch_ids": [batch.uid]}) - export_task.wait_till_done() - stream = export_task.get_buffered_stream() - - batch_data_rows_global_keys = [dr.json["data_row"]["global_key"] for dr in stream] - - assert batch_data_rows_global_keys == global_keys + assert batch.size == len(set(data_rows)) def test_media_type(client, project: Project, rand_gen): From 564dbc1bbe23413e8d57d95cab569b7941cb730d Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 08:13:27 -0500 Subject: [PATCH 08/10] changed to just export --- libs/labelbox/tests/integration/test_send_to_annotate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/labelbox/tests/integration/test_send_to_annotate.py b/libs/labelbox/tests/integration/test_send_to_annotate.py index 01844c95b..4338985b5 100644 --- a/libs/labelbox/tests/integration/test_send_to_annotate.py +++ b/libs/labelbox/tests/integration/test_send_to_annotate.py @@ -1,4 +1,4 @@ -from labelbox import UniqueIds, OntologyBuilder, LabelingFrontend, Project, Ontology, Client +from labelbox import UniqueIds, Project, Ontology, Client from labelbox.schema.conflict_resolution_strategy import ConflictResolutionStrategy from typing import List @@ -47,7 +47,7 @@ def test_send_to_annotate_include_annotations( destination_batches = list(destination_project.batches()) assert len(destination_batches) == 1 - export_task = destination_project.export(filters={"batch_ids": [destination_batches[0].uid]}) + export_task = destination_project.export() export_task.wait_till_done() stream = export_task.get_buffered_stream() From f1aa5a84c64eb2f688dbd46f51b5b0a4fccbac1a Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 08:14:39 -0500 Subject: [PATCH 09/10] changed conftest file --- libs/labelbox/tests/integration/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/labelbox/tests/integration/conftest.py b/libs/labelbox/tests/integration/conftest.py index 610573686..844933388 100644 --- a/libs/labelbox/tests/integration/conftest.py +++ b/libs/labelbox/tests/integration/conftest.py @@ -316,8 +316,8 @@ def export_v2_test_helpers() -> Type[ExportV2Helpers]: def big_dataset_data_row_ids(big_dataset: Dataset): export_task = big_dataset.export() export_task.wait_till_done() - stream = export_task.get_stream() - yield [json.loads(dr.json_str)["data_row"]["id"] for dr in stream] + stream = export_task.get_buffered_stream() + yield [dr.json["data_row"]["id"] for dr in stream] @pytest.fixture(scope='function') From dcd6ab37789527e944f61c13d5c4123642e7d67b Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 29 May 2024 09:27:31 -0500 Subject: [PATCH 10/10] removed export_task file --- libs/labelbox/src/labelbox/schema/export_task.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/labelbox/src/labelbox/schema/export_task.py b/libs/labelbox/src/labelbox/schema/export_task.py index 8f87318f2..b00c9166a 100644 --- a/libs/labelbox/src/labelbox/schema/export_task.py +++ b/libs/labelbox/src/labelbox/schema/export_task.py @@ -919,4 +919,5 @@ def get_stream( @staticmethod def get_task(client, task_id): """Returns the task with the given id.""" - return ExportTask(Task.get_task(client, task_id)) \ No newline at end of file + return ExportTask(Task.get_task(client, task_id)) + \ No newline at end of file