21
21
from ...spatialimages import HeaderDataError
22
22
from ...volumeutils import sys_is_le
23
23
from ...wrapstruct import WrapStructError
24
+ from ... import imageglobals
24
25
25
26
from nose .tools import assert_true , assert_false
26
27
32
33
from ...testing import data_path
33
34
34
35
from ...tests import test_spatialimages as tsi
35
- from ...tests .test_wrapstruct import _TestWrapStructBase
36
+ from ...tests .test_wrapstruct import _TestLabeledWrapStruct
36
37
37
38
MGZ_FNAME = os .path .join (data_path , 'test.mgz' )
38
39
@@ -371,9 +372,16 @@ def check_dtypes(self, expected, actual):
371
372
assert_equal (expected .newbyteorder ('>' ), actual )
372
373
373
374
374
- class TestMGHHeader (_TestWrapStructBase ):
375
+ class TestMGHHeader (_TestLabeledWrapStruct ):
375
376
header_class = MGHHeader
376
377
378
+ def _set_something_into_hdr (self , hdr ):
379
+ hdr ['dims' ] = [4 , 3 , 2 , 1 ]
380
+
381
+ def get_bad_bb (self ):
382
+ return b'\xff ' + bytes (self .header_class ._hdrdtype .itemsize )
383
+
384
+ # Update tests to account for big-endian requirement
377
385
def test_general_init (self ):
378
386
hdr = self .header_class ()
379
387
# binaryblock has length given by header data dtype
@@ -385,10 +393,6 @@ def test_general_init(self):
385
393
# effect
386
394
hdr = self .header_class (check = False )
387
395
388
- def _set_something_into_hdr (self , hdr ):
389
- hdr ['dims' ] = [4 , 3 , 2 , 1 ]
390
-
391
- # Update tests to account for big-endian requirement
392
396
def test__eq__ (self ):
393
397
# Test equal and not equal
394
398
hdr1 = self .header_class ()
@@ -470,3 +474,14 @@ def check_fix(self, *args, **kwargs):
470
474
assert_raises (Exception , DC , hdr .binaryblock )
471
475
hdr = DC (hdr .binaryblock , check = False )
472
476
hdr2 = hdr .as_byteswapped ('>' )
477
+
478
+ def test_checks (self ):
479
+ # Test header checks
480
+ hdr_t = self .header_class ()
481
+ # _dxer just returns the diagnostics as a string
482
+ # Default hdr is OK
483
+ assert_equal (self ._dxer (hdr_t ), '' )
484
+ # Version should be 1
485
+ hdr = hdr_t .copy ()
486
+ hdr ['version' ] = 2
487
+ assert_equal (self ._dxer (hdr ), 'Unknown MGH format version' )
0 commit comments