Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ This section highlights all the necessary preparation steps required before send
To collaborate efficiently, please read through this section and follow them.

* [Checking the coding style](#checking-the-coding-style)
* [Licensing information](#licensing-information)
* [Unit testing](#unit-testing)
* [Building documentation](#building-the-documentation)
* [Signing your work](#signing-your-work)
Expand All @@ -63,7 +64,9 @@ python -m pip install -U -r requirements-dev.txt
./runtests.sh --autofix
```

License information: all source code files should start with this paragraph:
#### Licensing information
All source code files should start with this paragraph:

```
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -119,6 +122,12 @@ If it requires any other external packages, please make sure:
- the new test `test_[module_name].py` is added to the `exclude_cases` in [`./tests/min_tests.py`](./tests/min_tests.py) so that
the minimal CI runner will not execute it.

##### Testing data
Testing data such as images and binary files should not be placed in the source code repository.
Please deploy them to a reliable file sharing location (the current preferred one is [https://github.com/Project-MONAI/MONAI-extra-test-data/releases](https://github.com/Project-MONAI/MONAI-extra-test-data/releases)).
At test time, the URLs within `tests/testing_data/data_config.json` are accessible
via the APIs provided in `tests.utils`: `tests.utils.testing_data_config` and `tests.utils.download_url_or_skip_test`.

_If it's not tested, it's broken_

All new functionality should be accompanied by an appropriate set of tests.
Expand Down
29 changes: 12 additions & 17 deletions tests/test_resample_to_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,24 @@
import unittest

from monai.transforms import Compose, EnsureChannelFirstd, LoadImaged, ResampleToMatch, SaveImaged
from tests.utils import assert_allclose, download_url_or_skip_test
from tests.utils import assert_allclose, download_url_or_skip_test, testing_data_config


class TestResampleToMatch(unittest.TestCase):
def setUp(self):
self.fnames = []
for key in ("0000_t2_tse_tra_4", "0000_ep2d_diff_tra_7"):
fname = os.path.join(os.path.dirname(__file__), "testing_data", f"test_{key}.nii.gz")
url = testing_data_config("images", key, "url")
hash_type = testing_data_config("images", key, "hash_type")
hash_val = testing_data_config("images", key, "hash_val")
download_url_or_skip_test(url=url, filepath=fname, hash_type=hash_type, hash_val=hash_val)
self.fnames.append(fname)

def test_correct(self):
with tempfile.TemporaryDirectory() as temp_dir:
url_1 = (
"https://github.com/rcuocolo/PROSTATEx_masks/raw/master/Files/"
+ "lesions/Images/T2/ProstateX-0000_t2_tse_tra_4.nii.gz"
)
url_2 = (
"https://github.com/rcuocolo/PROSTATEx_masks/raw/master/Files/"
+ "lesions/Images/ADC/ProstateX-0000_ep2d_diff_tra_7.nii.gz"
)
fname_1 = os.path.join(temp_dir, "file1.nii.gz")
fname_2 = os.path.join(temp_dir, "file2.nii.gz")
md5_1 = "adb3f1c4db66a6481c3e4a2a3033c7d5"
md5_2 = "f12a11ad0ebb0b1876e9e010564745d2"
download_url_or_skip_test(url=url_1, filepath=fname_1, hash_val=md5_1)
download_url_or_skip_test(url=url_2, filepath=fname_2, hash_val=md5_2)

loader = Compose([LoadImaged(("im1", "im2")), EnsureChannelFirstd(("im1", "im2"))])
data = loader({"im1": fname_1, "im2": fname_2})
data = loader({"im1": self.fnames[0], "im2": self.fnames[1]})

im_mod, meta = ResampleToMatch()(data["im2"], data["im2_meta_dict"], data["im1_meta_dict"])
# for visual inspection
Expand Down
29 changes: 12 additions & 17 deletions tests/test_resample_to_matchd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import unittest

from monai.transforms import Compose, CopyItemsd, EnsureChannelFirstd, Lambda, LoadImaged, ResampleToMatchd, SaveImaged
from tests.utils import assert_allclose, download_url_or_skip_test
from tests.utils import assert_allclose, download_url_or_skip_test, testing_data_config


def update_fname(d):
Expand All @@ -23,23 +23,18 @@ def update_fname(d):


class TestResampleToMatchd(unittest.TestCase):
def setUp(self):
self.fnames = []
for key in ("0000_t2_tse_tra_4", "0000_ep2d_diff_tra_7"):
fname = os.path.join(os.path.dirname(__file__), "testing_data", f"test_{key}.nii.gz")
url = testing_data_config("images", key, "url")
hash_type = testing_data_config("images", key, "hash_type")
hash_val = testing_data_config("images", key, "hash_val")
download_url_or_skip_test(url=url, filepath=fname, hash_type=hash_type, hash_val=hash_val)
self.fnames.append(fname)

def test_correct(self):
with tempfile.TemporaryDirectory() as temp_dir:
url_1 = (
"https://github.com/rcuocolo/PROSTATEx_masks/raw/master/Files/"
+ "lesions/Images/T2/ProstateX-0000_t2_tse_tra_4.nii.gz"
)
url_2 = (
"https://github.com/rcuocolo/PROSTATEx_masks/raw/master/Files/"
+ "lesions/Images/ADC/ProstateX-0000_ep2d_diff_tra_7.nii.gz"
)
fname_1 = os.path.join(temp_dir, "file1.nii.gz")
fname_2 = os.path.join(temp_dir, "file2.nii.gz")
md5_1 = "adb3f1c4db66a6481c3e4a2a3033c7d5"
md5_2 = "f12a11ad0ebb0b1876e9e010564745d2"
download_url_or_skip_test(url=url_1, filepath=fname_1, hash_val=md5_1)
download_url_or_skip_test(url=url_2, filepath=fname_2, hash_val=md5_2)

transforms = Compose(
[
LoadImaged(("im1", "im2")),
Expand All @@ -50,7 +45,7 @@ def test_correct(self):
SaveImaged("im3", output_dir=temp_dir, output_postfix="", separate_folder=False),
]
)
data = transforms({"im1": fname_1, "im2": fname_2})
data = transforms({"im1": self.fnames[0], "im2": self.fnames[1]})
assert_allclose(data["im1"].shape, data["im3"].shape)


Expand Down
10 changes: 10 additions & 0 deletions tests/testing_data/data_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/Prostate_T2W_AX_1.nii",
"hash_type": "sha256",
"hash_val": "a14231f539c0f365a5f83f2a046969a9b9870e56ffd126fd8e7242364d25938a"
},
"0000_t2_tse_tra_4": {
"url": "https://github.com/rcuocolo/PROSTATEx_masks/raw/master/Files/lesions/Images/T2/ProstateX-0000_t2_tse_tra_4.nii.gz",
"hash_type": "md5",
"hash_val": "adb3f1c4db66a6481c3e4a2a3033c7d5"
},
"0000_ep2d_diff_tra_7": {
"url": "https://github.com/rcuocolo/PROSTATEx_masks/raw/master/Files/lesions/Images/ADC/ProstateX-0000_ep2d_diff_tra_7.nii.gz",
"hash_type": "md5",
"hash_val": "f12a11ad0ebb0b1876e9e010564745d2"
}
},
"models": {
Expand Down