Skip to content

Commit

Permalink
Fix: Codacy static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaharsh committed Jan 31, 2024
1 parent 78252da commit 2de1ea0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
14 changes: 10 additions & 4 deletions MRdataset/tests/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
THIS_DIR = Path(__file__).parent.resolve()


def sample_dicom_dataset(tmp_path='/tmp'):
def sample_dicom_dataset(tmp_path=None):
if not tmp_path:
tmp_path = tempfile.gettempdir()
DATA_ARCHIVE = THIS_DIR / 'resources/example_dicom_data.zip'
DATA_ROOT = Path(tmp_path)
output_dir = DATA_ROOT / 'example_dicom_data'
Expand All @@ -27,7 +29,9 @@ def sample_dicom_dataset(tmp_path='/tmp'):
return DATA_ROOT / 'example_dicom_data'


def sample_bids_dataset(tmp_path='/tmp'):
def sample_bids_dataset(tmp_path=None):
if not tmp_path:
tmp_path = tempfile.gettempdir()
DATA_ARCHIVE = THIS_DIR / 'resources/example_bids_data.zip'
if not DATA_ARCHIVE.exists():
raise FileNotFoundError(f'Please download example datasets from '
Expand All @@ -40,7 +44,9 @@ def sample_bids_dataset(tmp_path='/tmp'):
return DATA_ROOT / 'example_bids_dataset'


def sample_vertical_dataset(tmp_path='/tmp'):
def sample_vertical_dataset(tmp_path=None):
if not tmp_path:
tmp_path = tempfile.gettempdir()
DATA_ARCHIVE = THIS_DIR / 'resources/vertical.zip'
DATA_ROOT = Path(tmp_path)
output_dir = DATA_ROOT / 'vertical/'
Expand Down Expand Up @@ -109,7 +115,7 @@ def make_compliant_bids_dataset(num_subjects,
try:
with open(filepath, "r") as read_file:
parameters = json.load(read_file)
except (FileNotFoundError, ValueError) as e:
except (FileNotFoundError, ValueError):
continue
parameters['RepetitionTime'] = repetition_time
parameters['EchoTrainLength'] = echo_train_length
Expand Down
3 changes: 0 additions & 3 deletions MRdataset/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import pytest
from hypothesis import given, settings, HealthCheck

from MRdataset import BaseDataset, import_dataset
from MRdataset.dicom import DicomDataset
from MRdataset.tests.conftest import dcm_dataset_strategy, \
vertical_dataset_strategy
from MRdataset.tests.simulate import make_compliant_test_dataset
from MRdataset.utils import convert2ascii

THIS_DIR = Path(__file__).parent.resolve()
Expand Down
16 changes: 8 additions & 8 deletions MRdataset/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_dataset(num_subjects,

for seq_id in seq_ids:
mrd_num_subjects = set()
for subject, session, run, seq in mrd.traverse_horizontal(seq_id):
for subject, _, _, seq in mrd.traverse_horizontal(seq_id):
mrd_num_subjects.add(subject)
assert seq['RepetitionTime'].get_value() == repetition_time
assert seq['EchoTrainLength'].get_value() == echo_train_length
Expand All @@ -49,18 +49,18 @@ def test_dataset(num_subjects,
def test_config_dict():
fake_ds_dir = make_compliant_bids_dataset(1, 1, 1, 1)
with pytest.raises(FileNotFoundError):
mrd = import_dataset(fake_ds_dir, config_path='non-existent.json',
output_dir=fake_ds_dir, name='test_dataset',
ds_format='bids')
import_dataset(fake_ds_dir, config_path='non-existent.json',
output_dir=fake_ds_dir, name='test_dataset',
ds_format='bids')


def test_invalid_output_dir():
fake_ds_dir = make_compliant_bids_dataset(1, 1, 1, 1)
with pytest.raises(TypeError):
mrd = import_dataset(fake_ds_dir,
config_path=THIS_DIR / 'resources/bids-config.json',
output_dir=1, name='test_dataset',
ds_format='bids')
import_dataset(fake_ds_dir,
config_path=THIS_DIR / 'resources/bids-config.json',
output_dir=1, name='test_dataset',
ds_format='bids')


def test_invalid_datatype():
Expand Down

0 comments on commit 2de1ea0

Please sign in to comment.