Skip to content

Commit 16eb766

Browse files
author
Kevin Kim
committed
Use fixtures instead
1 parent 3d8b596 commit 16eb766

File tree

5 files changed

+62
-56
lines changed

5 files changed

+62
-56
lines changed

tests/integration/conftest.py

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -119,49 +119,6 @@ def get_invites(client):
119119
return invites
120120

121121

122-
def wait_for_data_row_processing(client, data_row):
123-
"""
124-
Do not use. Only for testing.
125-
126-
Returns DataRow after waiting for it to finish processing media_attributes.
127-
Some tests, specifically ones that rely on label export, rely on
128-
DataRow be fully processed with media_attributes
129-
"""
130-
data_row_id = data_row.uid
131-
timeout_seconds = 60
132-
while True:
133-
data_row = client.get_data_row(data_row_id)
134-
if data_row.media_attributes:
135-
return data_row
136-
timeout_seconds -= 2
137-
if timeout_seconds <= 0:
138-
raise TimeoutError(
139-
f"Timed out waiting for DataRow '{data_row_id}' to finish processing media_attributes"
140-
)
141-
time.sleep(2)
142-
143-
144-
def wait_for_label_processing(project):
145-
"""
146-
Do not use. Only for testing.
147-
148-
Returns Label after waiting for it to finish processing.
149-
If `project.labels()` is called before label is fully processed,
150-
it may return an empty set
151-
"""
152-
timeout_seconds = 10
153-
while True:
154-
label = project.labels().get_one()
155-
if label is not None:
156-
return label
157-
timeout_seconds -= 2
158-
if timeout_seconds <= 0:
159-
raise TimeoutError(
160-
f"Timed out waiting for label for project '{project.uid}' to finish processing"
161-
)
162-
time.sleep(2)
163-
164-
165122
@pytest.fixture
166123
def queries():
167124
return SimpleNamespace(cancel_invite=cancel_invite,
@@ -347,7 +304,7 @@ def configured_project(project, client, rand_gen, image_url):
347304

348305
@pytest.fixture
349306
def configured_project_with_label(client, rand_gen, image_url, project, dataset,
350-
datarow):
307+
datarow, wait_for_label_processing):
351308
"""Project with a connected dataset, having one datarow
352309
Project contains an ontology with 1 bbox tool
353310
Additionally includes a create_label method for any needed extra labels
@@ -450,3 +407,58 @@ def configured_project_with_complex_ontology(client, rand_gen, image_url):
450407
yield [project, data_row]
451408
dataset.delete()
452409
project.delete()
410+
411+
412+
@pytest.fixture
413+
def wait_for_data_row_processing():
414+
"""
415+
Do not use. Only for testing.
416+
417+
Returns DataRow after waiting for it to finish processing media_attributes.
418+
Some tests, specifically ones that rely on label export, rely on
419+
DataRow be fully processed with media_attributes
420+
"""
421+
422+
def func(client, data_row):
423+
data_row_id = data_row.uid
424+
timeout_seconds = 60
425+
while True:
426+
data_row = client.get_data_row(data_row_id)
427+
print(f"dr {data_row}")
428+
if data_row.media_attributes:
429+
return data_row
430+
timeout_seconds -= 2
431+
if timeout_seconds <= 0:
432+
raise TimeoutError(
433+
f"Timed out waiting for DataRow '{data_row_id}' to finish processing media_attributes"
434+
)
435+
time.sleep(2)
436+
437+
return func
438+
439+
440+
@pytest.fixture
441+
def wait_for_label_processing():
442+
"""
443+
Do not use. Only for testing.
444+
445+
Returns Label after waiting for it to finish processing.
446+
If `project.labels()` is called before label is fully processed,
447+
it may return an empty set
448+
"""
449+
450+
def func(project):
451+
timeout_seconds = 10
452+
while True:
453+
label = project.labels().get_one()
454+
print(f"LABEL: {label}")
455+
if label is not None:
456+
return label
457+
timeout_seconds -= 2
458+
if timeout_seconds <= 0:
459+
raise TimeoutError(
460+
f"Timed out waiting for label for project '{project.uid}' to finish processing"
461+
)
462+
time.sleep(2)
463+
464+
return func

tests/integration/test_data_row_media_attributes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from time import sleep
2-
from conftest import wait_for_data_row_processing
3-
4-
5-
def test_export_empty_media_attributes(client, configured_project_with_label):
1+
def test_export_empty_media_attributes(client, configured_project_with_label,
2+
wait_for_data_row_processing):
63
project, _, data_row, _ = configured_project_with_label
74
data_row = wait_for_data_row_processing(client, data_row)
85
labels = list(project.label_generator())

tests/integration/test_data_row_metadata.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from datetime import datetime
2-
from time import sleep
32

43
import pytest
54
import uuid
65

7-
from conftest import wait_for_data_row_processing
86
from labelbox import DataRow, Dataset
97
from labelbox.schema.data_row_metadata import DataRowMetadataField, DataRowMetadata, DataRowMetadataKind, DeleteDataRowMetadata, \
108
DataRowMetadataOntology, _parse_metadata_schema
@@ -91,7 +89,8 @@ def make_named_metadata(dr_id) -> DataRowMetadata:
9189
return metadata
9290

9391

94-
def test_export_empty_metadata(client, configured_project_with_label):
92+
def test_export_empty_metadata(client, configured_project_with_label,
93+
wait_for_data_row_processing):
9594
project, _, data_row, _ = configured_project_with_label
9695
data_row = wait_for_data_row_processing(client, data_row)
9796
labels = project.label_generator()

tests/integration/test_export.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from time import sleep
21
import uuid
32

4-
from conftest import wait_for_data_row_processing
53
from labelbox.data.annotation_types.annotation import ObjectAnnotation
64
from labelbox.schema.annotation_import import LabelImport
75

86

97
def test_export_annotations_nested_checklist(
10-
client, configured_project_with_complex_ontology):
8+
client, configured_project_with_complex_ontology,
9+
wait_for_data_row_processing):
1110
project, data_row = configured_project_with_complex_ontology
1211
data_row = wait_for_data_row_processing(client, data_row)
1312

tests/integration/test_project_setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime, timedelta, timezone
22
import json
33
import time
4-
import time
54

65
import pytest
76

0 commit comments

Comments
 (0)