|
10 | 10 |
|
11 | 11 | from nose.tools import assert_true |
12 | 12 | import numpy as np |
13 | | -from numpy.testing import assert_equal, dec |
| 13 | +from numpy.testing import assert_equal, assert_raises, dec |
14 | 14 |
|
15 | 15 | from .. import (read_geometry, read_morph_data, read_annot, read_label, |
16 | 16 | write_geometry, write_morph_data, write_annot) |
17 | 17 |
|
18 | 18 | from ...tests.nibabel_data import get_nibabel_data |
| 19 | +from ...fileslice import strided_scalar |
19 | 20 |
|
20 | 21 |
|
21 | 22 | DATA_SDIR = 'fsaverage' |
@@ -99,6 +100,25 @@ def test_morph_data(): |
99 | 100 | assert_equal(curv2, curv) |
100 | 101 |
|
101 | 102 |
|
| 103 | +def test_write_morph_data(): |
| 104 | + """Test write_morph_data edge cases""" |
| 105 | + values = np.arange(20, dtype='>f4') |
| 106 | + okay_shapes = [(20,), (20, 1), (20, 1, 1), (1, 20)] |
| 107 | + bad_shape = (10, 2) |
| 108 | + big_num = np.iinfo('i4').max + 1 |
| 109 | + with InTemporaryDirectory(): |
| 110 | + for shape in okay_shapes: |
| 111 | + write_morph_data('test.curv', values.reshape(shape)) |
| 112 | + # Check ordering is preserved, regardless of shape |
| 113 | + assert_equal(values, read_morph_data('test.curv')) |
| 114 | + assert_raises(ValueError, write_morph_data, 'test.curv', |
| 115 | + np.zeros(shape), big_num) |
| 116 | + assert_raises(ValueError, write_morph_data, 'test.curv', |
| 117 | + values.reshape(bad_shape)) |
| 118 | + assert_raises(ValueError, write_morph_data, 'test.curv', |
| 119 | + strided_scalar((big_num,))) |
| 120 | + |
| 121 | + |
102 | 122 | @freesurfer_test |
103 | 123 | def test_annot(): |
104 | 124 | """Test IO of .annot""" |
|
0 commit comments