Skip to content

Commit 461898c

Browse files
committed
Replace pytest with unittest
1 parent a88ce78 commit 461898c

File tree

3 files changed

+45
-47
lines changed

3 files changed

+45
-47
lines changed

python/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tmp:
2828
mkdir $@
2929

3030
tmp/all-done: .dockerignore .gitignore Dockerfile main.py pyproject.toml
31-
docker container run --publish 443:443\
31+
docker container run --publish 8000:8000\
3232
$$(command -v nvidia-container-toolkit > /dev/null && printf '%s' '--gpus all') \
3333
$$(test -t 0 && printf '%s' '--interactive --tty') \
3434
--detach-keys 'ctrl-^,ctrl-^' \

python/main.py

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import subprocess
1212
import sys
1313
import time
14+
import unittest
1415
from functools import lru_cache
1516
from io import BytesIO
1617
from pathlib import Path
@@ -24,7 +25,6 @@
2425
import numpy as np
2526
import pandas as pd
2627
import pydicom
27-
import pytest
2828
import requests
2929
import torch
3030
from fastapi import Body, FastAPI, Request, UploadFile, status
@@ -145,50 +145,51 @@ def dcm2dictmetadata(ds: pydicom.dataset.Dataset) -> dict[str, dict[str, str]]:
145145
client = TestClient(app)
146146

147147

148-
def app_url() -> str:
149-
return "http://0.0.0.0:443"
150-
151-
152-
def test_upload_files() -> None:
153-
with Path("./prm/1-1.dcm").open("rb") as file:
154-
files = {"files": ("./prm/1-1.dcm", file, "application/dicom")}
155-
response = client.post(app_url() + "/upload_files", files=files)
148+
class TestEndpoints(unittest.TestCase):
149+
def app_url(self: TestEndpoints) -> str:
150+
return "http://0.0.0.0:8000"
151+
152+
def test_upload_files(self: TestEndpoints) -> None:
153+
with Path("./prm/1-1.dcm").open("rb") as file:
154+
files = {"files": ("./prm/1-1.dcm", file, "application/dicom")}
155+
response = client.post(self.app_url() + "/upload_files", files=files)
156+
if response.status_code != status.HTTP_200_OK:
157+
raise AssertionError
158+
UploadFilesResponse.model_validate(response.json())
159+
160+
def test_submit_button(self: TestEndpoints) -> None:
161+
test_options = {
162+
"skip_deidentification": False,
163+
"clean_image": True,
164+
"annotation": False,
165+
"retain_safe_private": False,
166+
"retain_uids": False,
167+
"retain_device_identity": False,
168+
"retain_patient_characteristics": False,
169+
"date_processing": "remove",
170+
"retain_descriptors": False,
171+
"patient_pseudo_id_prefix": "OrgX - ",
172+
}
173+
response = client.post(self.app_url() + "/submit_button", json=test_options)
156174
if response.status_code != status.HTTP_200_OK:
157175
raise AssertionError
158-
UploadFilesResponse.model_validate(response.json())
159-
160-
161-
def test_submit_button() -> None:
162-
test_options = {
163-
"skip_deidentification": False,
164-
"clean_image": True,
165-
"annotation": False,
166-
"retain_safe_private": False,
167-
"retain_uids": False,
168-
"retain_device_identity": False,
169-
"retain_patient_characteristics": False,
170-
"date_processing": "remove",
171-
"retain_descriptors": False,
172-
"patient_pseudo_id_prefix": "OrgX - ",
173-
}
174-
response = client.post(app_url() + "/submit_button", json=test_options)
175-
if response.status_code != status.HTTP_200_OK:
176-
raise AssertionError
177-
json_response = response.json()
178-
desired_hash = "cd6e8eae4006ca7b150c3217667de6b6f7b435f93961d182e72b4da7773884a9"
179-
hasher = hashlib.sha256()
180-
block_size = 65536
181-
with Path(json_response[0][1]).open("rb") as file:
182-
buf = file.read(block_size)
183-
while len(buf) > 0:
184-
hasher.update(buf)
185-
buf = file.read(block_size)
186-
generated_hash = hasher.hexdigest()
187-
if desired_hash != generated_hash:
188-
msg = "E: Generated hash doesn't match"
189-
raise ValueError(
190-
msg,
176+
json_response = response.json()
177+
desired_hash = (
178+
"cd6e8eae4006ca7b150c3217667de6b6f7b435f93961d182e72b4da7773884a9"
191179
)
180+
hasher = hashlib.sha256()
181+
block_size = 65536
182+
with Path(json_response[0][1]).open("rb") as file:
183+
buf = file.read(block_size)
184+
while len(buf) > 0:
185+
hasher.update(buf)
186+
buf = file.read(block_size)
187+
generated_hash = hasher.hexdigest()
188+
if desired_hash != generated_hash:
189+
msg = "E: Generated hash doesn't match"
190+
raise ValueError(
191+
msg,
192+
)
192193

193194

194195
@app.get("/check_existence_of_clean")
@@ -1525,9 +1526,7 @@ def meddisc() -> None:
15251526
ssl_keyfile="tmp/privkey.pem",
15261527
)
15271528
else:
1528-
results = pytest.main(["-rA", "-o", "cache_dir=tmp", __file__])
1529-
if results.value != 0: # type: ignore[attr-defined]
1530-
sys.exit(results)
1529+
unittest.main()
15311530

15321531

15331532
def main_cli() -> None:

python/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ dependencies = [
99
"pydicom==2.4.4",
1010
"pylibjpeg-libjpeg==2.1.0",
1111
"pylibjpeg==2.0.0",
12-
"pytest==8.1.1",
1312
"python-multipart==0.0.9",
1413
"segment-anything@https://api.github.com/repos/facebookresearch/segment-anything/tarball/main",
1514
"tensorflow==2.16.1",

0 commit comments

Comments
 (0)