|
41 | 41 | [0.0, -1.0, 0.0, 2.0],
|
42 | 42 | [0.0, 0.0, 0.0, 1.0]], dtype=np.float32)
|
43 | 43 |
|
| 44 | +BIG_CODES = ('>', 'big', 'BIG', 'b', 'be', 'B', 'BE') |
| 45 | +LITTLE_CODES = ('<', 'little', 'l', 'le', 'L', 'LE') |
| 46 | + |
| 47 | +if sys_is_le: |
| 48 | + BIG_CODES += ('swapped', 's', 'S', '!') |
| 49 | + LITTLE_CODES += ('native', 'n', 'N', '=', '|', 'i', 'I') |
| 50 | +else: |
| 51 | + BIG_CODES += ('native', 'n', 'N', '=', '|', 'i', 'I') |
| 52 | + LITTLE_CODES += ('swapped', 's', 'S', '!') |
| 53 | + |
| 54 | + |
44 | 55 |
|
45 | 56 | def test_read_mgh():
|
46 | 57 | # test.mgz was generated by the following command
|
@@ -258,12 +269,6 @@ def test_mgh_load_fileobj():
|
258 | 269 | assert_array_equal(img.get_data(), img2.get_data())
|
259 | 270 |
|
260 | 271 |
|
261 |
| -def test_mgh_reject_little_endian(): |
262 |
| - bblock = b'\x00' * MGHHeader.template_dtype.itemsize |
263 |
| - with assert_raises(ValueError): |
264 |
| - MGHHeader(bblock, endianness='<') |
265 |
| - |
266 |
| - |
267 | 272 | def test_mgh_affine_default():
|
268 | 273 | hdr = MGHHeader()
|
269 | 274 | hdr['goodRASFlag'] = 0
|
@@ -303,26 +308,29 @@ def test_mghheader_default_structarr():
|
303 | 308 | assert_equal(hdr['ti'], 0)
|
304 | 309 | assert_equal(hdr['fov'], 0)
|
305 | 310 |
|
306 |
| - big_codes = ('>', 'big', 'BIG', 'b', 'be', 'B', 'BE') |
307 |
| - little_codes = ('<', 'little', 'l', 'le', 'L', 'LE') |
308 |
| - |
309 |
| - if sys_is_le: |
310 |
| - big_codes += ('swapped', 's', 'S', '!') |
311 |
| - little_codes += ('native', 'n', 'N', '=', '|', 'i', 'I') |
312 |
| - else: |
313 |
| - big_codes += ('native', 'n', 'N', '=', '|', 'i', 'I') |
314 |
| - little_codes += ('swapped', 's', 'S', '!') |
315 |
| - |
316 |
| - for endianness in big_codes: |
| 311 | + for endianness in (None,) + BIG_CODES: |
317 | 312 | hdr2 = MGHHeader.default_structarr(endianness=endianness)
|
318 | 313 | assert_equal(hdr2, hdr)
|
319 | 314 | assert_equal(hdr2.newbyteorder('>'), hdr)
|
320 | 315 |
|
321 |
| - for endianness in little_codes: |
| 316 | + for endianness in LITTLE_CODES: |
322 | 317 | with assert_raises(ValueError):
|
323 | 318 | MGHHeader.default_structarr(endianness=endianness)
|
324 | 319 |
|
325 | 320 |
|
| 321 | +def test_byteswap(): |
| 322 | + hdr = MGHHeader() |
| 323 | + |
| 324 | + for endianness in BIG_CODES: |
| 325 | + hdr2 = hdr.as_byteswapped(endianness) |
| 326 | + assert_true(hdr2 is not hdr) |
| 327 | + assert_equal(hdr2, hdr) |
| 328 | + |
| 329 | + for endianness in (None,) + LITTLE_CODES: |
| 330 | + with assert_raises(ValueError): |
| 331 | + hdr.as_byteswapped(endianness) |
| 332 | + |
| 333 | + |
326 | 334 | class TestMGHImage(tsi.TestSpatialImage, tsi.MmapImageMixin):
|
327 | 335 | """ Apply general image tests to MGHImage
|
328 | 336 | """
|
|
0 commit comments