2121from ...spatialimages import HeaderDataError
2222from ...volumeutils import sys_is_le
2323from ...wrapstruct import WrapStructError
24+ from ... import imageglobals
2425
2526from nose .tools import assert_true , assert_false
2627
3233from ...testing import data_path
3334
3435from ...tests import test_spatialimages as tsi
35- from ...tests .test_wrapstruct import _TestWrapStructBase
36+ from ...tests .test_wrapstruct import _TestLabeledWrapStruct
3637
3738MGZ_FNAME = os .path .join (data_path , 'test.mgz' )
3839
@@ -371,9 +372,16 @@ def check_dtypes(self, expected, actual):
371372 assert_equal (expected .newbyteorder ('>' ), actual )
372373
373374
374- class TestMGHHeader (_TestWrapStructBase ):
375+ class TestMGHHeader (_TestLabeledWrapStruct ):
375376 header_class = MGHHeader
376377
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
377385 def test_general_init (self ):
378386 hdr = self .header_class ()
379387 # binaryblock has length given by header data dtype
@@ -385,10 +393,6 @@ def test_general_init(self):
385393 # effect
386394 hdr = self .header_class (check = False )
387395
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
392396 def test__eq__ (self ):
393397 # Test equal and not equal
394398 hdr1 = self .header_class ()
@@ -470,3 +474,14 @@ def check_fix(self, *args, **kwargs):
470474 assert_raises (Exception , DC , hdr .binaryblock )
471475 hdr = DC (hdr .binaryblock , check = False )
472476 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