Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Aug 21, 2024
1 parent a43fbba commit 46c650a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import math
import os
from functools import partial
from pathlib import Path
from typing import List
from unittest import mock

import numpy as np
import pytest
Expand Down Expand Up @@ -304,12 +306,16 @@ def test_run_m_script_no_output_file_error(tmp_path, mocker):
"clinica.pipelines.statistics_volume.statistics_volume_utils._run_matlab_script_with_matlab",
return_value=None,
)
(tmp_path / "spm_home_folder").mkdir()

with pytest.raises(
RuntimeError,
match="Output matrix",
):
run_m_script(m_file)
with mock.patch.dict(
os.environ, {"SPM_HOME": str(tmp_path / "spm_home_folder")}
):
run_m_script(m_file)


def test_run_m_script(tmp_path, mocker):
Expand All @@ -327,8 +333,10 @@ def test_run_m_script(tmp_path, mocker):
"clinica.pipelines.statistics_volume.statistics_volume_utils._run_matlab_script_with_matlab",
return_value=None,
)
(tmp_path / "spm_home_folder").mkdir()

assert run_m_script(m_file) == str(expected_output_file)
with mock.patch.dict(os.environ, {"SPM_HOME": str(tmp_path / "spm_home_folder")}):
assert run_m_script(m_file) == str(expected_output_file)


@pytest.mark.parametrize(
Expand Down
20 changes: 18 additions & 2 deletions test/unittests/utils/test_spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@

import pytest

from clinica.utils.exceptions import ClinicaMissingDependencyError

def test_spm_standalone_is_available_no_env_variable():

def test_spm_standalone_is_available_no_env_variable_error():
from clinica.utils.spm import use_spm_standalone_if_available

with pytest.raises(
ClinicaMissingDependencyError,
match="Clinica could not find spm software: the SPM_HOME variable is not set.",
):
use_spm_standalone_if_available()


def test_spm_standalone_is_available_warning(tmp_path):
from clinica.utils.spm import use_spm_standalone_if_available

(tmp_path / "spm_home_folder").mkdir()
with pytest.warns(
UserWarning,
match=re.escape(
Expand All @@ -17,7 +30,10 @@ def test_spm_standalone_is_available_no_env_variable():
"$SPMSTANDALONE_HOME, and $MCR_HOME"
),
):
assert not use_spm_standalone_if_available()
with mock.patch.dict(
os.environ, {"SPM_HOME": str(tmp_path / "spm_home_folder")}
):
assert not use_spm_standalone_if_available()


def test_spm_standalone_is_available(tmp_path, mocker):
Expand Down

0 comments on commit 46c650a

Please sign in to comment.