Skip to content

Commit f742a36

Browse files
author
Diego Ardila
committed
re-remove boto, remove type annotations impossible in 3.6
2 parents 54da72f + b6c2f0a commit f742a36

File tree

10 files changed

+34
-55
lines changed

10 files changed

+34
-55
lines changed

.circleci/config.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ jobs:
3333
- run:
3434
name: Pytest Test Cases
3535
command: | # Run test suite, uses NUCLEUS_TEST_API_KEY env variable
36-
poetry run coverage run -m pytest
36+
mkdir test_results
37+
poetry run coverage run --include=nucleus/* -m pytest --junitxml=test_results/junit.xml
3738
poetry run coverage report
3839
poetry run coverage html
3940
4041
- store_test_results:
4142
path: htmlcov
43+
44+
- store_test_results:
45+
path: test_results
46+
47+
- store_artifacts:
48+
path: test_results
4249
pypi_publish:
4350
docker:
4451
- image: cimg/python:3.6

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,9 @@ pre-commit install
169169
```
170170

171171
**Best practices for testing:**
172-
(1). Before running pytest, please make sure to authenticate into AWS, since some of the unit tests rely on AWs resources:
172+
(1). Please run pytest from the root directory of the repo, i.e.
173173
```
174-
gimme_okta_aws_creds
175-
```
176-
177-
(2). Please run pytest from the root directory of the repo, i.e.
178-
```
179-
pytest tests/test_dataset.py
174+
poetry pytest tests/test_dataset.py
180175
```
181176

182177

nucleus/annotation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ class BoxAnnotation(Annotation): # pylint: disable=R0902
120120
y: Union[float, int]
121121
width: Union[float, int]
122122
height: Union[float, int]
123-
annotation_id: Optional[str] = None
124-
metadata: Optional[Dict] = None
125123
reference_id: Optional[str] = None
126124
item_id: Optional[str] = None
125+
annotation_id: Optional[str] = None
126+
metadata: Optional[Dict] = None
127127

128128
def __post_init__(self):
129129
self._check_ids()
@@ -165,10 +165,10 @@ def to_payload(self) -> dict:
165165
class PolygonAnnotation(Annotation):
166166
label: str
167167
vertices: List[Any]
168-
annotation_id: Optional[str] = None
169-
metadata: Optional[Dict] = None
170168
reference_id: Optional[str] = None
171169
item_id: Optional[str] = None
170+
annotation_id: Optional[str] = None
171+
metadata: Optional[Dict] = None
172172

173173
def __post_init__(self):
174174
self._check_ids()

nucleus/prediction.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from typing import Dict, Optional, List, Any
42
from .annotation import (
53
BoxAnnotation,
@@ -30,7 +28,7 @@ class SegmentationPrediction(SegmentationAnnotation):
3028
# No need to define init or to_payload methods because
3129
# we default to functions defined in the parent class
3230
@classmethod
33-
def from_json(cls, payload: dict) -> SegmentationPrediction:
31+
def from_json(cls, payload: dict):
3432
return cls(
3533
mask_url=payload[MASK_URL_KEY],
3634
annotations=[
@@ -78,7 +76,7 @@ def to_payload(self) -> dict:
7876
return payload
7977

8078
@classmethod
81-
def from_json(cls, payload: dict) -> BoxPrediction:
79+
def from_json(cls, payload: dict):
8280
geometry = payload.get(GEOMETRY_KEY, {})
8381
return cls(
8482
label=payload.get(LABEL_KEY, 0),
@@ -123,7 +121,7 @@ def to_payload(self) -> dict:
123121
return payload
124122

125123
@classmethod
126-
def from_json(cls, payload: dict) -> PolygonPrediction:
124+
def from_json(cls, payload: dict):
127125
geometry = payload.get(GEOMETRY_KEY, {})
128126
return cls(
129127
label=payload.get(LABEL_KEY, 0),

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ pytest = "^6.2.3"
4747
pylint = "^2.7.4"
4848
black = "^20.8b1"
4949
flake8 = "^3.9.1"
50-
boto3 = "^1.17.51"
50+
mypy = "^0.812"
51+
coverage = "^5.5"
5152

5253

5354
[build-system]

tests/helpers.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from pathlib import Path
2+
import time
23
from urllib.parse import urlparse
3-
import boto3
4+
45
from nucleus import DatasetItem, BoxPrediction
5-
import time
66

77
PRESIGN_EXPIRY_SECONDS = 60 * 60 * 24 * 2 # 2 days
88

99
TEST_MODEL_NAME = "[PyTest] Test Model"
10-
TEST_MODEL_REFERENCE = "[PyTest] Test Model Reference" + str(time.time())
1110
TEST_MODEL_RUN = "[PyTest] Test Model Run"
1211
TEST_DATASET_NAME = "[PyTest] Test Dataset"
1312
TEST_SLICE_NAME = "[PyTest] Test Slice"
@@ -37,30 +36,6 @@
3736
]
3837

3938

40-
def get_signed_url(url):
41-
bucket, key = get_s3_details(url)
42-
return s3_sign(bucket, key)
43-
44-
45-
def get_s3_details(url):
46-
# Expects S3 URL format to be https://<BUCKET>.s3.amazonaws.com/<KEY>
47-
parsed = urlparse(url)
48-
bucket = parsed.netloc[: parsed.netloc.find(".")]
49-
return bucket, parsed.path[1:]
50-
51-
52-
def s3_sign(bucket, key):
53-
s3 = boto3.client("s3")
54-
return s3.generate_presigned_url(
55-
ClientMethod="get_object",
56-
Params={
57-
"Bucket": bucket,
58-
"Key": key,
59-
},
60-
ExpiresIn=PRESIGN_EXPIRY_SECONDS,
61-
)
62-
63-
6439
def reference_id_from_url(url):
6540
return Path(url).name
6641

tests/test_annotation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ def test_box_gt_upload_update(dataset):
209209

210210
def test_box_gt_upload_ignore(dataset):
211211
annotation = BoxAnnotation(**TEST_BOX_ANNOTATIONS[0])
212+
213+
print(annotation)
214+
212215
response = dataset.annotate(annotations=[annotation])
213216

214217
assert response["annotations_processed"] == 1
@@ -222,10 +225,11 @@ def test_box_gt_upload_ignore(dataset):
222225
"reference_id"
223226
]
224227
annotation_update = BoxAnnotation(**annotation_update_params)
228+
225229
# Default behavior is ignore.
226230
response = dataset.annotate(annotations=[annotation_update])
227231

228-
assert response["annotations_processed"] == 1
232+
assert response["annotations_processed"] == 0
229233
assert response["annotations_ignored"] == 1
230234

231235
response = dataset.refloc(annotation.reference_id)["annotations"]["box"]
@@ -286,7 +290,7 @@ def test_polygon_gt_upload_ignore(dataset):
286290
# Default behavior is ignore.
287291
response = dataset.annotate(annotations=[annotation_update])
288292

289-
assert response["annotations_processed"] == 1
293+
assert response["annotations_processed"] == 0
290294
assert response["annotations_ignored"] == 1
291295

292296
response = dataset.refloc(annotation.reference_id)["annotations"][

tests/test_indexing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
from helpers import (
4-
get_signed_url,
54
TEST_INDEX_EMBEDDINGS_FILE,
65
TEST_IMG_URLS,
76
TEST_DATASET_NAME,

tests/test_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
import time
23
import pytest
34
from nucleus import (
45
Dataset,
@@ -19,7 +20,6 @@
1920
)
2021
from helpers import (
2122
TEST_MODEL_NAME,
22-
TEST_MODEL_REFERENCE,
2323
TEST_MODEL_RUN,
2424
TEST_PREDS,
2525
)
@@ -46,8 +46,9 @@ def test_repr(test_object: any):
4646
def test_model_creation_and_listing(CLIENT, dataset):
4747
models_before = CLIENT.list_models()
4848

49+
model_reference = "model_" + str(time.time())
4950
# Creation
50-
model = CLIENT.add_model(TEST_MODEL_NAME, TEST_MODEL_REFERENCE)
51+
model = CLIENT.add_model(TEST_MODEL_NAME, model_reference)
5152
m_run = model.create_run(TEST_MODEL_RUN, dataset, TEST_PREDS)
5253
m_run.commit()
5354

tests/test_prediction.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import pytest
2-
2+
import time
33
from helpers import (
44
TEST_DATASET_NAME,
55
TEST_MODEL_NAME,
6-
TEST_MODEL_REFERENCE,
76
TEST_MODEL_RUN,
87
TEST_IMG_URLS,
98
TEST_BOX_PREDICTIONS,
@@ -58,7 +57,7 @@ def model_run(CLIENT):
5857
assert ERROR_PAYLOAD not in response.json()
5958

6059
model = CLIENT.add_model(
61-
name=TEST_MODEL_NAME, reference_id=TEST_MODEL_REFERENCE
60+
name=TEST_MODEL_NAME, reference_id="model_" + str(time.time())
6261
)
6362

6463
run = model.create_run(name=TEST_MODEL_RUN, dataset=ds, predictions=[])
@@ -176,7 +175,7 @@ def test_box_pred_upload_ignore(model_run):
176175
# Default behavior is ignore.
177176
response = model_run.predict(annotations=[prediction_update])
178177

179-
assert response["predictions_processed"] == 1
178+
assert response["predictions_processed"] == 0
180179
assert response["predictions_ignored"] == 1
181180

182181
response = model_run.refloc(prediction.reference_id)["box"]
@@ -231,7 +230,7 @@ def test_polygon_pred_upload_ignore(model_run):
231230
# Default behavior is ignore.
232231
response = model_run.predict(annotations=[prediction_update])
233232

234-
assert response["predictions_processed"] == 1
233+
assert response["predictions_processed"] == 0
235234
assert response["predictions_ignored"] == 1
236235

237236
response = model_run.refloc(prediction.reference_id)["polygon"]

0 commit comments

Comments
 (0)