-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_models.py
More file actions
118 lines (95 loc) · 3.14 KB
/
Copy pathtest_models.py
File metadata and controls
118 lines (95 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import time
from pathlib import Path
import pytest
from nucleus import (
BoxPrediction,
Dataset,
DatasetItem,
Model,
ModelRun,
NucleusClient,
UploadResponse,
)
from nucleus.constants import (
DATASET_ID_KEY,
ERROR_ITEMS,
ERROR_PAYLOAD,
IGNORED_ITEMS,
NEW_ITEMS,
UPDATED_ITEMS,
)
from .helpers import (
TEST_BOX_PREDICTIONS,
TEST_MODEL_NAME,
TEST_MODEL_RUN,
TEST_PREDS,
assert_box_prediction_matches_dict,
get_uuid,
)
def test_reprs():
# Have to define here in order to have access to all relevant objects
def test_repr(test_object: any):
assert eval(str(test_object)) == test_object
client = NucleusClient(api_key="fake_key")
test_repr(
Model(
client=client,
model_id="fake_model_id",
name="fake_name",
reference_id="fake_reference_id",
metadata={"fake": "metadata"},
)
)
test_repr(
ModelRun(
client=client,
dataset_id="fake_dataset_id",
model_run_id="fake_model_run_id",
)
)
def test_model_creation_and_listing(CLIENT, dataset):
model_reference = "model_" + str(time.time())
# Creation
model_name = TEST_MODEL_NAME + get_uuid()
model = CLIENT.create_model(model_name, model_reference)
model_run = TEST_MODEL_RUN + get_uuid()
m_run = model.create_run(model_run, dataset, TEST_PREDS)
assert isinstance(model, Model)
assert isinstance(m_run, ModelRun)
# List the models
ms = CLIENT.models
# Get a model
m = CLIENT.get_model(model.id)
m = CLIENT.get_model(m_run.model_run_id)
assert m == model
assert model in ms
# Delete the model
CLIENT.delete_model(model.id)
ms = CLIENT.models
assert model not in ms
# Until we fully remove the other endpoints (and then migrate those tests) just quickly test the basics of the new ones since they are basically just simple wrappers around the old ones.
def test_new_model_endpoints(CLIENT, dataset: Dataset):
model_reference = "model_" + str(time.time())
model = CLIENT.create_model(TEST_MODEL_NAME, model_reference)
predictions = [BoxPrediction(**TEST_BOX_PREDICTIONS[0])]
dataset.upload_predictions(model, predictions=predictions)
# Skip this until we have a way of avoiding launching pyspark jobs as a consequence of CI.
# dataset.calculate_evaluation_metrics(model)
predictions_export = dataset.export_predictions(model)
assert_box_prediction_matches_dict(
predictions_export["box"][0], TEST_BOX_PREDICTIONS[0]
)
predictions_iloc = dataset.predictions_iloc(model, 0)
assert_box_prediction_matches_dict(
predictions_iloc["box"][0], TEST_BOX_PREDICTIONS[0]
)
predictions_refloc = dataset.predictions_refloc(
model, predictions[0].reference_id
)
assert_box_prediction_matches_dict(
predictions_refloc["box"][0], TEST_BOX_PREDICTIONS[0]
)
prediction_loc = dataset.prediction_loc(
model, predictions[0].reference_id, predictions[0].annotation_id
)
assert_box_prediction_matches_dict(prediction_loc, TEST_BOX_PREDICTIONS[0])