|
25 | 25 | import pytest |
26 | 26 |
|
27 | 27 | from nifreeze.data.pet import PET |
28 | | -from nifreeze.model.pet import PETModel |
| 28 | +from nifreeze.model.pet import ( |
| 29 | + DEFAULT_TIMEFRAME_MIDPOINT_TOL, |
| 30 | + FIRST_MIDPOINT_VALUE_ERROR_MSG, |
| 31 | + LAST_MIDPOINT_VALUE_ERROR_MSG, |
| 32 | + TIMEPOINT_XLIM_DATA_MISSING_ERROR_MSG, |
| 33 | + PETModel, |
| 34 | +) |
29 | 35 |
|
30 | 36 |
|
31 | 37 | @pytest.fixture |
@@ -71,13 +77,38 @@ def test_petmodel_fit_predict(random_dataset): |
71 | 77 |
|
72 | 78 |
|
73 | 79 | @pytest.mark.random_pet_data(5, (4, 4, 4), np.asarray([10.0, 20.0, 30.0, 40.0, 50.0]), 60.0) |
74 | | -def test_petmodel_invalid_init(random_dataset): |
75 | | - with pytest.raises(TypeError): |
| 80 | +def test_petmodel_init_mandatory_attr_errors(random_dataset): |
| 81 | + with pytest.raises(TypeError, match=TIMEPOINT_XLIM_DATA_MISSING_ERROR_MSG): |
76 | 82 | PETModel(dataset=random_dataset) |
77 | 83 |
|
| 84 | + xlim = 55.0 |
| 85 | + with pytest.raises(TypeError, match=TIMEPOINT_XLIM_DATA_MISSING_ERROR_MSG): |
| 86 | + PETModel(dataset=random_dataset, xlim=xlim) |
| 87 | + |
| 88 | + timepoints = np.array([20, 30, 40, 50, 60], dtype=np.float32) |
| 89 | + with pytest.raises(TypeError, match=TIMEPOINT_XLIM_DATA_MISSING_ERROR_MSG): |
| 90 | + PETModel(dataset=random_dataset, timepoints=timepoints) |
| 91 | + |
78 | 92 |
|
79 | 93 | @pytest.mark.random_pet_data(5, (4, 4, 4), np.asarray([10.0, 20.0, 30.0, 40.0, 50.0]), 60.0) |
80 | | -def test_petmodel_time_check(random_dataset): |
81 | | - bad_times = np.array([0, 10, 20, 30, 50], dtype=np.float32) |
82 | | - with pytest.raises(ValueError): |
83 | | - PETModel(dataset=random_dataset, timepoints=bad_times, xlim=60.0) |
| 94 | +def test_petmodel_first_midpoint_error(random_dataset): |
| 95 | + timepoints = np.array([0, 10, 20, 30, 50], dtype=np.float32) |
| 96 | + xlim = 60.0 |
| 97 | + with pytest.raises(ValueError, match=FIRST_MIDPOINT_VALUE_ERROR_MSG): |
| 98 | + PETModel(dataset=random_dataset, timepoints=timepoints, xlim=xlim) |
| 99 | + |
| 100 | + timepoints[0] = DEFAULT_TIMEFRAME_MIDPOINT_TOL |
| 101 | + with pytest.raises(ValueError, match=FIRST_MIDPOINT_VALUE_ERROR_MSG): |
| 102 | + PETModel(dataset=random_dataset, timepoints=timepoints, xlim=xlim) |
| 103 | + |
| 104 | + |
| 105 | +@pytest.mark.random_pet_data(5, (4, 4, 4), np.asarray([10.0, 20.0, 30.0, 40.0, 50.0]), 40.0) |
| 106 | +def test_petmodel_last_midpoint_error(random_dataset): |
| 107 | + xlim = 45.0 |
| 108 | + timepoints = np.array([5, 10, 20, 30, 50], dtype=np.float32) |
| 109 | + with pytest.raises(ValueError, match=LAST_MIDPOINT_VALUE_ERROR_MSG): |
| 110 | + PETModel(dataset=random_dataset, timepoints=timepoints, xlim=xlim) |
| 111 | + |
| 112 | + timepoints[-1] = xlim - DEFAULT_TIMEFRAME_MIDPOINT_TOL |
| 113 | + with pytest.raises(ValueError, match=LAST_MIDPOINT_VALUE_ERROR_MSG): |
| 114 | + PETModel(dataset=random_dataset, timepoints=timepoints, xlim=xlim) |
0 commit comments