Skip to content

Commit b95d1b8

Browse files
author
Val Brodsky
committed
Convert tests that do now require many data rows prebuilt to a simpler project fixture
1 parent 48285e4 commit b95d1b8

File tree

6 files changed

+64
-65
lines changed

6 files changed

+64
-65
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
2-
addopts = -s -vv --reruns 5 --reruns-delay 10 --durations=20
2+
addopts = -s -vv
33
markers =
44
slow: marks tests as slow (deselect with '-m "not slow"')

tests/integration/annotation_import/conftest.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,17 +486,12 @@ def initial_dataset(client, rand_gen):
486486

487487

488488
@pytest.fixture
489-
def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
489+
def configured_project(client, configured_project_without_data_rows,
490+
initial_dataset, ontology, rand_gen, image_url):
490491
start_time = time.time()
491492
dataset = initial_dataset
492-
project = client.create_project(
493-
name=rand_gen(str),
494-
queue_mode=QueueMode.Batch,
495-
)
496-
editor = list(
497-
client.get_labeling_frontends(
498-
where=LabelingFrontend.name == "editor"))[0]
499-
project.setup(editor, ontology)
493+
project = configured_project_without_data_rows
494+
500495
data_row_ids = []
501496
# print("Before creating data rows ", time.time() - start_time)
502497
num_rows = 0

tests/integration/annotation_import/test_bulk_import_request.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,40 @@
2525
"""
2626

2727

28-
def test_create_from_url(configured_project):
28+
def test_create_from_url(project):
2929
name = str(uuid.uuid4())
3030
url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson"
3131

32-
bulk_import_request = configured_project.upload_annotations(name=name,
33-
annotations=url,
34-
validate=False)
32+
bulk_import_request = project.upload_annotations(name=name,
33+
annotations=url,
34+
validate=False)
3535

36-
assert bulk_import_request.project() == configured_project
36+
assert bulk_import_request.project() == project
3737
assert bulk_import_request.name == name
3838
assert bulk_import_request.input_file_url == url
3939
assert bulk_import_request.error_file_url is None
4040
assert bulk_import_request.status_file_url is None
4141
assert bulk_import_request.state == BulkImportRequestState.RUNNING
4242

4343

44-
def test_validate_file(configured_project):
44+
def test_validate_file(project_with_ontology):
4545
name = str(uuid.uuid4())
4646
url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson"
4747
with pytest.raises(MALValidationError):
48-
configured_project.upload_annotations(name=name,
49-
annotations=url,
50-
validate=True)
48+
project_with_ontology.upload_annotations(name=name,
49+
annotations=url,
50+
validate=True)
5151
#Schema ids shouldn't match
5252

5353

54-
def test_create_from_objects(configured_project, predictions,
54+
def test_create_from_objects(configured_project_without_data_rows, predictions,
5555
annotation_import_test_helpers):
5656
name = str(uuid.uuid4())
5757

58-
bulk_import_request = configured_project.upload_annotations(
58+
bulk_import_request = configured_project_without_data_rows.upload_annotations(
5959
name=name, annotations=predictions)
6060

61-
assert bulk_import_request.project() == configured_project
61+
assert bulk_import_request.project() == configured_project_without_data_rows
6262
assert bulk_import_request.name == name
6363
assert bulk_import_request.error_file_url is None
6464
assert bulk_import_request.status_file_url is None
@@ -105,17 +105,17 @@ def test_create_from_local_file(tmp_path, predictions, configured_project,
105105
bulk_import_request.input_file_url, predictions)
106106

107107

108-
def test_get(client, configured_project):
108+
def test_get(client, configured_project_without_data_rows):
109109
name = str(uuid.uuid4())
110110
url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson"
111-
configured_project.upload_annotations(name=name,
112-
annotations=url,
113-
validate=False)
111+
configured_project_without_data_rows.upload_annotations(name=name,
112+
annotations=url,
113+
validate=False)
114114

115115
bulk_import_request = BulkImportRequest.from_name(
116-
client, project_id=configured_project.uid, name=name)
116+
client, project_id=configured_project_without_data_rows.uid, name=name)
117117

118-
assert bulk_import_request.project() == configured_project
118+
assert bulk_import_request.project() == configured_project_without_data_rows
119119
assert bulk_import_request.name == name
120120
assert bulk_import_request.input_file_url == url
121121
assert bulk_import_request.error_file_url is None
@@ -158,14 +158,13 @@ def test_validate_ndjson_uuid(tmp_path, configured_project, predictions):
158158

159159

160160
@pytest.mark.slow
161-
def test_wait_till_done(rectangle_inference, configured_project):
161+
def test_wait_till_done(rectangle_inference,
162+
configured_project_without_data_rows):
162163
name = str(uuid.uuid4())
163-
url = configured_project.client.upload_data(content=parser.dumps(
164-
[rectangle_inference]),
165-
sign=True)
166-
bulk_import_request = configured_project.upload_annotations(name=name,
167-
annotations=url,
168-
validate=False)
164+
url = configured_project_without_data_rows.client.upload_data(
165+
content=parser.dumps([rectangle_inference]), sign=True)
166+
bulk_import_request = configured_project_without_data_rows.upload_annotations(
167+
name=name, annotations=url, validate=False)
169168

170169
assert len(bulk_import_request.inputs) == 1
171170
bulk_import_request.wait_until_done()

tests/integration/annotation_import/test_data_types.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def create_data_row_for_project(project, dataset, data_row_ndjson, batch_name):
125125
[data_row.uid], # sample of data row objects
126126
5 # priority between 1(Highest) - 5(lowest)
127127
)
128-
project.data_row_ids.append(data_row.uid)
129128

130129
return data_row
131130

@@ -135,12 +134,12 @@ def create_data_row_for_project(project, dataset, data_row_ndjson, batch_name):
135134
AudioData, ConversationData, DicomData, DocumentData, HTMLData, ImageData,
136135
TextData
137136
])
138-
def test_import_data_types(client, configured_project, initial_dataset,
139-
rand_gen, data_row_json_by_data_type,
140-
annotations_by_data_type, data_type_class):
137+
def test_import_data_types(client, project, initial_dataset, rand_gen,
138+
data_row_json_by_data_type, annotations_by_data_type,
139+
data_type_class):
141140

142-
project = configured_project
143-
project_id = configured_project.uid
141+
project = project
142+
project_id = project.uid
144143
dataset = initial_dataset
145144

146145
set_project_media_type_from_data_type(project, data_type_class)
@@ -261,11 +260,11 @@ def test_import_data_types_v2(client, configured_project, initial_dataset,
261260

262261

263262
@pytest.mark.parametrize('data_type, data_class, annotations', test_params)
264-
def test_import_label_annotations(client, configured_project, initial_dataset,
265-
data_row_json_by_data_type, data_type,
266-
data_class, annotations, rand_gen):
263+
def test_import_label_annotations(client, configured_project_without_data_rows,
264+
initial_dataset, data_row_json_by_data_type,
265+
data_type, data_class, annotations, rand_gen):
267266

268-
project = configured_project
267+
project = configured_project_without_data_rows
269268
dataset = initial_dataset
270269
set_project_media_type_from_data_type(project, data_class)
271270

@@ -297,7 +296,8 @@ def test_import_label_annotations(client, configured_project, initial_dataset,
297296
assert export_task.errors is None
298297
expected_annotations = get_annotation_comparison_dicts_from_labels(labels)
299298
actual_annotations = get_annotation_comparison_dicts_from_export(
300-
export_task.result, data_row.uid, configured_project.uid)
299+
export_task.result, data_row.uid,
300+
configured_project_without_data_rows.uid)
301301
assert actual_annotations == expected_annotations
302302
data_row.delete()
303303

tests/integration/conftest.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import re
6+
import sys
67
import time
78
import uuid
89
from enum import Enum
@@ -390,9 +391,21 @@ def initial_dataset(client, rand_gen):
390391

391392

392393
@pytest.fixture
393-
def configured_project(project, initial_dataset, client, rand_gen, image_url):
394+
def project_with_ontology(project):
395+
editor = list(
396+
project.client.get_labeling_frontends(
397+
where=LabelingFrontend.name == "editor"))[0]
398+
empty_ontology = {"tools": [], "classifications": []}
399+
project.setup(editor, empty_ontology)
400+
yield project
401+
402+
403+
@pytest.fixture
404+
def configured_project(project_with_ontology, initial_dataset, rand_gen,
405+
image_url):
394406
dataset = initial_dataset
395407
data_row_id = dataset.create_data_row(row_data=image_url).uid
408+
project = project_with_ontology
396409

397410
project.create_batch(
398411
rand_gen(str),
@@ -401,14 +414,7 @@ def configured_project(project, initial_dataset, client, rand_gen, image_url):
401414
)
402415
project.data_row_ids = [data_row_id]
403416

404-
editor = list(
405-
project.client.get_labeling_frontends(
406-
where=LabelingFrontend.name == "editor"))[0]
407-
empty_ontology = {"tools": [], "classifications": []}
408-
project.setup(editor, empty_ontology)
409417
yield project
410-
dataset.delete()
411-
project.delete()
412418

413419

414420
@pytest.fixture
@@ -833,6 +839,8 @@ def pytest_fixture_setup(fixturedef, request):
833839

834840
@pytest.fixture(scope='session', autouse=True)
835841
def print_perf_summary():
842+
print("Starting measurements\n", file=sys.stderr)
843+
836844
yield
837845

838846
sorted_dict = dict(
@@ -841,5 +849,6 @@ def print_perf_summary():
841849
slowest_fixtures = [
842850
(aaa, sorted_dict[aaa]) for aaa in islice(sorted_dict, num_of_entries)
843851
]
844-
print("\nTop slowest fixtures:\n", slowest_fixtures)
845-
print("Data row report:\n", pytest.data_row_report)
852+
print("\nTop slowest fixtures:\n", slowest_fixtures, file=sys.stderr)
853+
print("Data row report:\n", pytest.data_row_report, file=sys.stderr)
854+
# assert False

tests/integration/test_project.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ def test_attach_instructions(client, project):
171171

172172
@pytest.mark.skipif(condition=os.environ['LABELBOX_TEST_ENVIRON'] == "onprem",
173173
reason="new mutation does not work for onprem")
174-
def test_html_instructions(configured_project):
174+
def test_html_instructions(project_with_ontology):
175175
html_file_path = '/tmp/instructions.html'
176176
sample_html_str = "<html></html>"
177177

178178
with open(html_file_path, 'w') as file:
179179
file.write(sample_html_str)
180180

181-
configured_project.upsert_instructions(html_file_path)
182-
updated_ontology = configured_project.ontology().normalized
181+
project_with_ontology.upsert_instructions(html_file_path)
182+
updated_ontology = project_with_ontology.ontology().normalized
183183

184184
instructions = updated_ontology.pop('projectInstructions')
185185
assert requests.get(instructions).text == sample_html_str
@@ -200,10 +200,6 @@ def test_same_ontology_after_instructions(
200200
assert instructions is not None
201201

202202

203-
def test_queue_mode(configured_project: Project):
204-
assert configured_project.queue_mode == QueueMode.Batch
205-
206-
207203
def test_batches(project: Project, dataset: Dataset, image_url):
208204
task = dataset.create_data_rows([
209205
{
@@ -243,9 +239,9 @@ def test_create_batch_with_global_keys_async(project: Project, data_rows):
243239
assert batch_data_rows == set(data_rows)
244240

245241

246-
def test_media_type(client, configured_project: Project, rand_gen):
242+
def test_media_type(client, project: Project, rand_gen):
247243
# Existing project with no media_type
248-
assert isinstance(configured_project.media_type, MediaType)
244+
assert isinstance(project.media_type, MediaType)
249245

250246
# Update test
251247
project = client.create_project(name=rand_gen(str))

0 commit comments

Comments
 (0)