Skip to content

Commit 2bda625

Browse files
committed
tst: add some tests to extend coverage
1 parent d35f658 commit 2bda625

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

nitransforms/linear.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,6 @@ def __init__(self, transforms, reference=None):
227227
228228
"""
229229
super().__init__(reference=reference)
230-
if (
231-
transforms is None
232-
or np.shape(transforms)[0] < 1
233-
):
234-
raise TypeError(
235-
"Transforms should be a list of Affines or linear "
236-
"transforms matrix with at least two elements.")
237230

238231
self._matrix = np.stack([
239232
(
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#Insight Transform File V1.0
2+
#Transform 0
3+
Transform: AffineTransform_float_3_3
4+
Parameters: 1 0 0 0 1 0 0 0 1 0 0 0
5+
FixedParameters: 0 0 0
6+
7+
#Transform 1
8+
Transform: AffineTransform_float_3_3
9+
Parameters: 1 0 0 0 1 0 0 0 1 0 0 0
10+
FixedParameters: 0 0 0
11+
12+
#Transform 2
13+
Transform: AffineTransform_float_3_3
14+
Parameters: 1 0 0 0 1 0 0 0 1 0 0 0
15+
FixedParameters: 0 0 0
16+
17+
#Transform 3
18+
Transform: AffineTransform_float_3_3
19+
Parameters: 1 0 0 0 1 0 0 0 1 0 0 0
20+
FixedParameters: 0 0 0
21+
22+
#Transform 4
23+
Transform: AffineTransform_float_3_3
24+
Parameters: -1.53626 0.71973 -0.639856 -0.190759 -1.80082 -0.915885 0.502537 1.12532 0.275748 1.15383 3.96689 1.84349
25+
FixedParameters: 0 0 0
26+
27+
#Transform 5
28+
Transform: AffineTransform_float_3_3
29+
Parameters: -0.130507 -1.03017 2.08189 -1.51723 1.37849 -0.0890962 -0.656323 0.242694 2.15801 -3.00235 1.37109 0.162857
30+
FixedParameters: 0 0 0
31+
32+
#Transform 6
33+
Transform: AffineTransform_float_3_3
34+
Parameters: -1.55395 -0.36383 -0.17749 1.3387 -0.384534 -0.901462 -1.06598 -0.448228 -1.07535 0.75629 0.449768 -2.1133
35+
FixedParameters: 0 0 0
36+
37+
#Transform 7
38+
Transform: AffineTransform_float_3_3
39+
Parameters: 0.723719 -1.05617 -0.800562 -2.47048 -1.76301 -1.4447 -0.749896 1.29774 -1.48893 0.984286 1.12057 3.80071
40+
FixedParameters: 0 0 0
41+
42+
#Transform 8
43+
Transform: AffineTransform_float_3_3
44+
Parameters: 1.24025 -0.77628 0.618013 -0.523829 1.09471 1.66921 0.73753 -1.33588 -0.627659 -1.23816 -0.472076 -0.366883
45+
FixedParameters: 0 0 0

nitransforms/tests/test_linear.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@
3131
}
3232

3333

34+
def test_linear_typeerrors(data_path):
35+
"""Exercise errors in Affine creation."""
36+
with pytest.raises(TypeError):
37+
ntl.Affine([0.0])
38+
39+
with pytest.raises(TypeError):
40+
ntl.Affine(np.arange((3, 3, 3)))
41+
42+
with pytest.raises(TypeError):
43+
ntl.Affine(np.arange((3, 4)))
44+
45+
with pytest.raises(TypeError):
46+
ntl.Affine.from_filename(data_path / 'itktflist.tfm', fmt='itk')
47+
48+
49+
def test_loadsave(tmp_path, data_path):
50+
"""Test idempotency."""
51+
xfm = ntl.load(data_path / 'itktflist2.tfm', fmt='itk')
52+
xfm.to_filename(tmp_path / 'writtenout.tfm', fmt='itk')
53+
54+
assert (data_path / 'itktflist2.tfm').read_text() \
55+
== (tmp_path / 'writtenout.tfm').read_text()
56+
57+
3458
@pytest.mark.xfail(reason="Not fully implemented")
3559
@pytest.mark.parametrize('image_orientation', ['RAS', 'LAS', 'LPS', 'oblique'])
3660
@pytest.mark.parametrize('sw_tool', ['itk', 'fsl', 'afni', 'fs'])

0 commit comments

Comments
 (0)