Skip to content

Commit

Permalink
Merge 8a84e28 into 1d090b9
Browse files Browse the repository at this point in the history
  • Loading branch information
fepegar committed Oct 24, 2021
2 parents 1d090b9 + 8a84e28 commit 166d142
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Expand Up @@ -9,8 +9,7 @@ jobs:
unit:
strategy:
matrix:
# TODO: add windows-latest
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
python: ['3.6', '3.7', '3.8', '3.9']

runs-on: ${{ matrix.os }}
Expand Down
9 changes: 6 additions & 3 deletions tests/data/test_image.py
Expand Up @@ -2,9 +2,11 @@

"""Tests for Image."""

import sys
import copy
import tempfile

import pytest
import torch
import numpy as np
import nibabel as nib
Expand All @@ -20,6 +22,7 @@ def test_image_not_found(self):
with self.assertRaises(FileNotFoundError):
tio.ScalarImage('nopath')

@pytest.mark.skipif(sys.platform == 'win32', reason='Path not valid')
def test_wrong_path_value(self):
with self.assertRaises(RuntimeError):
tio.ScalarImage('~&./@#"!?X7=+')
Expand Down Expand Up @@ -157,7 +160,7 @@ def test_load_uint(self):
for dtype in np.uint16, np.uint32:
data = np.ones((3, 3, 3), dtype=dtype)
img = nib.Nifti1Image(data, affine)
with tempfile.NamedTemporaryFile(suffix='.nii') as f:
with tempfile.NamedTemporaryFile(suffix='.nii', delete=False) as f:
nib.save(img, f.name)
tio.ScalarImage(f.name).load()

Expand Down Expand Up @@ -204,9 +207,9 @@ def assert_shape(shape_in, shape_out):

def test_fast_gif(self):
with self.assertWarns(UserWarning):
with tempfile.NamedTemporaryFile(suffix='.gif') as f:
with tempfile.NamedTemporaryFile(suffix='.gif', delete=False) as f:
self.sample_subject.t1.to_gif(0, 0.0001, f.name)

def test_gif_rgb(self):
with tempfile.NamedTemporaryFile(suffix='.gif') as f:
with tempfile.NamedTemporaryFile(suffix='.gif', delete=False) as f:
tio.ScalarImage(tensor=torch.rand(3, 4, 5, 6)).to_gif(0, 1, f.name)
7 changes: 3 additions & 4 deletions tests/data/test_subject.py
Expand Up @@ -10,17 +10,16 @@ class TestSubject(TorchioTestCase):
"""Tests for `Subject`."""
def test_positional_args(self):
with self.assertRaises(ValueError):
with tempfile.NamedTemporaryFile() as f:
tio.Subject(tio.ScalarImage(f.name))
tio.Subject(0)

def test_input_dict(self):
with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(delete=False) as f:
input_dict = {'image': tio.ScalarImage(f.name)}
tio.Subject(input_dict)
tio.Subject(**input_dict)

def test_no_sample(self):
with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(delete=False) as f:
input_dict = {'image': tio.ScalarImage(f.name)}
subject = tio.Subject(input_dict)
with self.assertRaises(RuntimeError):
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.py
@@ -1,3 +1,4 @@
import os
import copy
import shutil
import random
Expand All @@ -16,7 +17,7 @@ class TorchioTestCase(unittest.TestCase):

def setUp(self):
"""Set up test fixtures, if any."""
self.dir = Path(tempfile.gettempdir()) / '.torchio_tests'
self.dir = Path(tempfile.gettempdir()) / os.urandom(24).hex()
self.dir.mkdir(exist_ok=True)
random.seed(42)
np.random.seed(42)
Expand Down
4 changes: 2 additions & 2 deletions torchio/datasets/ixi.py
Expand Up @@ -153,7 +153,7 @@ def _download(self, root, modalities):
url = self.base_url.format(modality=modality)
md5 = self.md5_dict[modality]

with NamedTemporaryFile(suffix='.tar') as f:
with NamedTemporaryFile(suffix='.tar', delete=False) as f:
download_and_extract_archive(
url,
download_root=modality_dir,
Expand Down Expand Up @@ -229,7 +229,7 @@ def _download(self, root):
return
print('Root directory for IXITiny not found:', root) # noqa: T001
print('Downloading...') # noqa: T001
with NamedTemporaryFile(suffix='.zip') as f:
with NamedTemporaryFile(suffix='.zip', delete=False) as f:
download_and_extract_archive(
self.url,
download_root=root,
Expand Down

0 comments on commit 166d142

Please sign in to comment.