|
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 |
| - write_geometry, write_annot) |
| 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'
|
@@ -92,6 +93,33 @@ def test_morph_data():
|
92 | 93 | curv = read_morph_data(curv_path)
|
93 | 94 | assert_true(-1.0 < curv.min() < 0)
|
94 | 95 | assert_true(0 < curv.max() < 1.0)
|
| 96 | + with InTemporaryDirectory(): |
| 97 | + new_path = 'test' |
| 98 | + write_morph_data(new_path, curv) |
| 99 | + curv2 = read_morph_data(new_path) |
| 100 | + assert_equal(curv2, curv) |
| 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_shapes = [(10, 2), (1, 1, 20, 1, 1)] |
| 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 | + # Windows 32-bit overflows Python int |
| 117 | + if np.dtype(np.int) != np.dtype(np.int32): |
| 118 | + assert_raises(ValueError, write_morph_data, 'test.curv', |
| 119 | + strided_scalar((big_num,))) |
| 120 | + for shape in bad_shapes: |
| 121 | + assert_raises(ValueError, write_morph_data, 'test.curv', |
| 122 | + values.reshape(shape)) |
95 | 123 |
|
96 | 124 |
|
97 | 125 | @freesurfer_test
|
|
0 commit comments