-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: allow for parallel test execution #180
Changes from 7 commits
9ad5456
b8c468d
f16620e
86abb74
9ce633c
eaa9ac6
89bab4e
bf860db
02df8fe
00178ec
0d5199f
a8522b5
d7ca843
3d41103
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
from .ops import * | ||
from .ops import ( | ||
BaseInput, | ||
BaseOp, | ||
BaseOutput, | ||
CentreCrop, | ||
ClipIntensity, | ||
Crop, | ||
HDF5Output, | ||
ImageAutoInput, | ||
ImageAutoOutput, | ||
ImageStatistics, | ||
MinMaxScale, | ||
NumpyOutput, | ||
Resample, | ||
Resize, | ||
StandardScale, | ||
StructureSetToSegmentation, | ||
WindowIntensity, | ||
Zoom, | ||
) | ||
|
||
__all__ = [ | ||
"ImageAutoInput", | ||
"ImageAutoOutput", | ||
"StructureSetToSegmentation", | ||
"BaseOp", | ||
"BaseInput", | ||
"BaseOutput", | ||
"CentreCrop", | ||
"ClipIntensity", | ||
"Crop", | ||
"HDF5Output", | ||
"ImageStatistics", | ||
"MinMaxScale", | ||
"NumpyOutput", | ||
"Resample", | ||
"Resize", | ||
"StandardScale", | ||
"WindowIntensity", | ||
"Zoom", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,64 +8,43 @@ | |
from imgtools.logging import logger | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
@pytest.fixture(scope="session") | ||
def curr_path(): | ||
return pathlib.Path(__file__).parent.parent.resolve().as_posix() | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
@pytest.fixture(scope='package') | ||
def dataset_path(curr_path): | ||
quebec_path = pathlib.Path(curr_path, 'data', 'Head-Neck-PET-CT') | ||
quebec_path = pathlib.Path(curr_path, "data", "Head-Neck-PET-CT") | ||
|
||
if not (quebec_path.exists() and len(list(quebec_path.glob('*'))) == 2): | ||
if not (quebec_path.exists() and len(list(quebec_path.glob("*"))) == 2): | ||
quebec_path.mkdir(parents=True, exist_ok=True) | ||
|
||
# Download QC dataset | ||
logger.info('Downloading the test dataset...') | ||
quebec_data_url = ( | ||
'https://github.com/bhklab/tcia_samples/blob/main/Head-Neck-PET-CT.zip?raw=true' | ||
) | ||
quebec_zip_path = pathlib.Path(quebec_path, 'Head-Neck-PET-CT.zip').as_posix() | ||
logger.info("Downloading the test dataset...") | ||
quebec_data_url = "https://github.com/bhklab/tcia_samples/blob/main/Head-Neck-PET-CT.zip?raw=true" | ||
quebec_zip_path = pathlib.Path(quebec_path, "Head-Neck-PET-CT.zip").as_posix() | ||
request.urlretrieve(quebec_data_url, quebec_zip_path) | ||
with ZipFile(quebec_zip_path, 'r') as zipfile: | ||
with ZipFile(quebec_zip_path, "r") as zipfile: | ||
zipfile.extractall(quebec_path) | ||
os.remove(quebec_zip_path) | ||
# os.remove(quebec_zip_path) | ||
else: | ||
logger.info('Data already downloaded...') | ||
logger.info("Data already downloaded...") | ||
|
||
output_path = pathlib.Path(curr_path, 'tests', 'temp').as_posix() | ||
output_path = pathlib.Path(curr_path, "tests", "temp").as_posix() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use pytest's built-in temporary directory fixtures for better test isolation. Instead of using a fixed 'temp' directory, consider using pytest's Example refactor: - output_path = pathlib.Path(curr_path, "tests", "temp").as_posix()
+ @pytest.fixture(scope="package")
+ def output_path(tmp_path_factory):
+ return tmp_path_factory.mktemp("output").as_posix()
|
||
quebec_path = quebec_path.as_posix() | ||
|
||
# Dataset name | ||
dataset_name = os.path.basename(quebec_path) | ||
imgtools_path = pathlib.Path(os.path.dirname(quebec_path), '.imgtools') | ||
imgtools_path = pathlib.Path(os.path.dirname(quebec_path), ".imgtools") | ||
|
||
# Defining paths for autopipeline and dataset component | ||
crawl_path = pathlib.Path(imgtools_path, f'imgtools_{dataset_name}.csv').as_posix() | ||
edge_path = pathlib.Path(imgtools_path, f'imgtools_{dataset_name}_edges.csv').as_posix() | ||
crawl_path = pathlib.Path(imgtools_path, f"imgtools_{dataset_name}.csv").as_posix() | ||
edge_path = pathlib.Path( | ||
imgtools_path, f"imgtools_{dataset_name}_edges.csv" | ||
).as_posix() | ||
# json_path = pathlib.Path(imgtools_path, f"imgtools_{dataset_name}.json").as_posix() # noqa: F841 | ||
|
||
yield quebec_path, output_path, crawl_path, edge_path | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def modalities_path(curr_path): | ||
qc_path = pathlib.Path(curr_path, 'data', 'Head-Neck-PET-CT', 'HN-CHUS-052') | ||
assert qc_path.exists(), 'Dataset not found' | ||
|
||
path = {} | ||
path['CT'] = pathlib.Path( | ||
qc_path, '08-27-1885-CA ORL FDG TEP POS TX-94629/3.000000-Merged-06362' | ||
).as_posix() | ||
path['RTSTRUCT'] = pathlib.Path( | ||
qc_path, | ||
'08-27-1885-OrophCB.0OrophCBTRTID derived StudyInstanceUID.-94629/Pinnacle POI-41418', | ||
).as_posix() | ||
path['RTDOSE'] = pathlib.Path( | ||
qc_path, | ||
'08-27-1885-OrophCB.0OrophCBTRTID derived StudyInstanceUID.-94629/11376', | ||
).as_posix() | ||
path['PT'] = pathlib.Path( | ||
qc_path, '08-27-1885-CA ORL FDG TEP POS TX-94629/532790.000000-LOR-RAMLA-44600' | ||
).as_posix() | ||
return path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Remove the commented cleanup code for better code maintainability
The commented cleanup (
os.remove(quebec_zip_path)
) is not critical since:Simply remove the commented line to maintain code cleanliness.
🔗 Analysis chain
Consider removing or justifying the commented cleanup code.
The commented-out cleanup code (
os.remove(quebec_zip_path)
) might lead to unnecessary disk space usage, especially in CI environments. If there's a specific reason for keeping the zip file, please document it; otherwise, consider removing the commented line.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 38
Script:
Length of output: 3062