File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 7
7
from nibabel .externals .six import BytesIO
8
8
9
9
from nibabel .testing import data_path
10
- from nibabel .testing import clear_and_catch_warnings
10
+ from nibabel .testing import clear_and_catch_warnings , assert_arr_dict_equal
11
11
from nose .tools import assert_equal , assert_raises , assert_true
12
12
from numpy .testing import assert_array_equal
13
13
@@ -460,3 +460,19 @@ def test_write_scalars_and_properties_name_too_long(self):
460
460
def test_str (self ):
461
461
trk = TrkFile .load (DATA ['complex_trk_fname' ])
462
462
str (trk ) # Simply test it's not failing when called.
463
+
464
+ def test_header_read_restore (self ):
465
+ # Test that reading a header restores the file position
466
+ trk_fname = DATA ['simple_trk_fname' ]
467
+ bio = BytesIO ()
468
+ bio .write (b'Along my very merry way' )
469
+ hdr_pos = bio .tell ()
470
+ hdr_from_fname = TrkFile ._read_header (trk_fname )
471
+ with open (trk_fname , 'rb' ) as fobj :
472
+ bio .write (fobj .read ())
473
+ bio .seek (hdr_pos )
474
+ # Check header is as expected
475
+ hdr_from_fname ['_offset_data' ] += hdr_pos # Correct for start position
476
+ assert_arr_dict_equal (TrkFile ._read_header (bio ), hdr_from_fname )
477
+ # Check fileobject file position has not changed
478
+ assert_equal (bio .tell (), hdr_pos )
Original file line number Diff line number Diff line change @@ -606,7 +606,7 @@ def _read_header(fileobj):
606
606
607
607
# Set the file position where it was, if it was previously open
608
608
if start_position is not None :
609
- fileobj .seek (start_position , os .SEEK_CUR )
609
+ fileobj .seek (start_position , os .SEEK_SET )
610
610
611
611
return header
612
612
You can’t perform that action at this time.
0 commit comments