Skip to content

Commit

Permalink
feat: refactor return_type test
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjermiah committed Feb 18, 2024
1 parent 799667e commit f2058e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/nbiatoolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
"NBIA_ENDPOINTS",
"version",
"__version__",
"downloadSingleSeries",
]
41 changes: 38 additions & 3 deletions tests/test_downloadSeries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from src.nbiatoolkit import NBIAClient
from sqlalchemy import over
from src.nbiatoolkit import NBIAClient, downloadSingleSeries
from tempfile import TemporaryDirectory
import os

Expand All @@ -9,8 +10,13 @@ def nbia_client():
return NBIAClient()


def test_downloadSeries(nbia_client):
seriesList = nbia_client.getSeries(Collection="NSCLC-Radiomics")
@pytest.fixture
def series_list(nbia_client):
return nbia_client.getSeries(Collection="NSCLC-Radiomics")


def test_downloadSeries(nbia_client, series_list):
seriesList = series_list
filePattern = (
"%PatientID/%Modality-%SeriesNumber-%SeriesInstanceUID/%InstanceNumber.dcm"
)
Expand All @@ -32,3 +38,32 @@ def test_downloadSeries(nbia_client):
assert len(modality_dir) == 1
assert modality_dir[0].startswith("CT")
assert os.path.isdir(os.path.join(tempdir, dir[0], modality_dir[0]))


def test_downloadSingleSeries(nbia_client, series_list):
seriesList = series_list
filePattern = (
"%PatientID/%Modality-%SeriesNumber-%SeriesInstanceUID/%InstanceNumber.dcm"
)
# create a temporary directory

with TemporaryDirectory() as tempdir:

downloadSingleSeries(
SeriesInstanceUID=seriesList[0]["SeriesInstanceUID"],
downloadDir=tempdir,
filePattern=filePattern,
overwrite=True,
api_headers=nbia_client.headers,
base_url=nbia_client.base_url,
log=nbia_client.logger,
)
dir = os.listdir(tempdir)

assert len(dir) == 1
assert os.path.isdir(os.path.join(tempdir, dir[0]))

modality_dir = os.listdir(os.path.join(tempdir, dir[0]))
assert len(modality_dir) == 1
assert modality_dir[0].startswith("CT")
assert os.path.isdir(os.path.join(tempdir, dir[0], modality_dir[0]))
8 changes: 8 additions & 0 deletions tests/test_new_query_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from src.nbiatoolkit import NBIAClient
from src.nbiatoolkit.auth import OAuth2
from src.nbiatoolkit.utils import *
from src.nbiatoolkit.logger import setup_logger
import pandas as pd


Expand Down Expand Up @@ -31,6 +32,13 @@ def test_nbia_properties(nbia_client):

assert nbia_client.logger is not None

nbia_client.logger = setup_logger(
name="NBIAClient", log_level="INFO", console_logging=True, log_file=None
)

assert nbia_client.return_type == "list"
nbia_client.return_type = "dataframe"


def test_tcga_collection_description(nbia_client: NBIAClient):
tcga_collection_description_df = nbia_client.getCollectionDescriptions(
Expand Down

0 comments on commit f2058e8

Please sign in to comment.