-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_models.py
More file actions
79 lines (67 loc) · 1.74 KB
/
Copy pathtest_models.py
File metadata and controls
79 lines (67 loc) · 1.74 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
from pathlib import Path
import time
import pytest
from nucleus import (
Dataset,
DatasetItem,
UploadResponse,
Model,
ModelRun,
BoxPrediction,
NucleusClient,
)
from nucleus.constants import (
NEW_ITEMS,
UPDATED_ITEMS,
IGNORED_ITEMS,
ERROR_ITEMS,
ERROR_PAYLOAD,
DATASET_ID_KEY,
)
from .helpers import (
TEST_MODEL_NAME,
TEST_MODEL_RUN,
TEST_PREDS,
)
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):
models_before = CLIENT.list_models()
model_reference = "model_" + str(time.time())
# Creation
model = CLIENT.add_model(TEST_MODEL_NAME, model_reference)
m_run = model.create_run(TEST_MODEL_RUN, dataset, TEST_PREDS)
m_run.commit()
assert isinstance(model, Model)
assert isinstance(m_run, ModelRun)
# List the models
ms = CLIENT.list_models()
# Get a model
m = CLIENT.get_model(model.id)
assert m == model
assert model in ms
assert list(set(ms) - set(models_before))[0] == model
# Delete the model
CLIENT.delete_model(model.id)
ms = CLIENT.list_models()
assert model not in ms
assert ms == models_before