Skip to content

Commit 560d9c6

Browse files
unit test nit
1 parent a6a13d6 commit 560d9c6

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import nucleus
1818
from nucleus.constants import SUCCESS_STATUS_CODES
1919

20+
from tests.helpers import TEST_DATASET_NAME, TEST_DATASET_ITEMS
2021

2122
assert 'NUCLEUS_PYTEST_API_KEY' in os.environ, \
2223
"You must set the 'NUCLEUS_PYTEST_API_KEY' environment variable to a valid " \
@@ -56,7 +57,7 @@ def _make_request_patch(
5657
monkeypatch_session.setattr(client, "_make_request", _make_request_patch)
5758
return client
5859

59-
@pytest.fixture()
60+
@pytest.fixture(scope='session')
6061
def dataset(CLIENT):
6162
ds = CLIENT.create_dataset(TEST_DATASET_NAME)
6263
ds.append(TEST_DATASET_ITEMS)

nucleus/model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def __repr__(self):
3030
def __eq__(self, other):
3131
return self.id == other.id
3232

33+
def __hash__(self):
34+
return hash(self.id)
35+
3336
def create_run(
3437
self,
3538
name: str,

tests/__init__.py

Whitespace-only changes.

tests/helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from pathlib import Path
22
from nucleus import DatasetItem, BoxPrediction
33

4-
TEST_MODEL_NAME = '[PyTest] Test Model'
4+
TEST_MODEL_NAME = '[PyTest] Test Model Name'
55
TEST_MODEL_REFERENCE = '[PyTest] Test Model Reference'
6-
TEST_MODEL_RUN = '[PyTest] Test Model Run'
6+
TEST_MODEL_RUN = '[PyTest] Test Model Run Reference'
77
TEST_DATASET_NAME = '[PyTest] Test Dataset'
88
TEST_SLICE_NAME = '[PyTest] Test Slice'
99
TEST_IMG_URLS = [
@@ -20,10 +20,10 @@
2020
DatasetItem(TEST_IMG_URLS[3], '4')
2121
]
2222
TEST_PREDS = [
23-
BoxPrediction('car', 0, 0, 100, 100, '1'),
24-
BoxPrediction('car', 0, 0, 100, 100, '2'),
25-
BoxPrediction('car', 0, 0, 100, 100, '3'),
26-
BoxPrediction('car', 0, 0, 100, 100, '4')
23+
BoxPrediction('[Pytest Box Prediction 1]', 0, 0, 100, 100, '1'),
24+
BoxPrediction('[Pytest Box Prediction 2]', 0, 0, 100, 100, '2'),
25+
BoxPrediction('[Pytest Box Prediction 3]', 0, 0, 100, 100, '3'),
26+
BoxPrediction('[Pytest Box Prediction 4]', 0, 0, 100, 100, '4')
2727
]
2828

2929
def reference_id_from_url(url):

tests/test_models.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,33 @@
1616
ERROR_PAYLOAD,
1717
DATASET_ID_KEY,
1818
)
19-
from helpers import (
19+
from .helpers import (
2020
TEST_MODEL_NAME,
2121
TEST_MODEL_REFERENCE,
2222
TEST_MODEL_RUN,
2323
TEST_PREDS
2424
)
2525

2626
def test_model_creation_and_listing(CLIENT, dataset):
27+
models_before = CLIENT.list_models()
28+
2729
# Creation
28-
m = CLIENT.add_model(TEST_MODEL_NAME, TEST_MODEL_REFERENCE)
29-
m_run = m.create_run(TEST_MODEL_RUN, dataset, TEST_PREDS)
30+
model = CLIENT.add_model(TEST_MODEL_NAME, TEST_MODEL_REFERENCE)
31+
m_run = model.create_run(TEST_MODEL_RUN, dataset, TEST_PREDS)
3032
m_run.commit()
3133

32-
assert isinstance(m, Model)
34+
assert isinstance(model, Model)
3335
assert isinstance(m_run, ModelRun)
3436

3537
# List the models
3638
ms = CLIENT.list_models()
3739

38-
assert m in ms
40+
assert model in ms
41+
assert list(set(ms) - set(models_before))[0] == model
3942

4043
# Delete the model
41-
CLIENT.delete_model(m.id)
44+
CLIENT.delete_model(model.id)
4245
ms = CLIENT.list_models()
4346

44-
assert m not in ms
47+
assert model not in ms
48+
assert ms == models_before

0 commit comments

Comments
 (0)