Skip to content

Commit 92153e6

Browse files
committed
TST+RF - add another endian swap test
Added test that asking for a byte-swapped header does result in a header that looks byte-swapped (with guess_endian). Some refactoring of code imports.
1 parent f6d1472 commit 92153e6

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

nibabel/ecat.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99
import warnings
1010

1111
import numpy as np
12-
import copy
13-
from nibabel.volumeutils import pretty_mapping, endian_codes,native_code,swapped_code
14-
from nibabel.volumeutils import native_code, swapped_code
15-
from nibabel.volumeutils import make_dt_codes, allopen
16-
17-
18-
from nibabel.spatialimages import SpatialImage, HeaderDataError, HeaderTypeError, ImageDataError
19-
from nibabel.volumeutils import allopen, array_from_file
20-
from .fileholders import FileHolderError, copy_file_map
21-
from .arrayproxy import ArrayProxy
2212

13+
from .volumeutils import (native_code, swapped_code, make_dt_codes,
14+
array_from_file)
15+
from .spatialimages import SpatialImage, ImageDataError
2316

2417

2518
MAINHDRSZ = 502

nibabel/tests/test_ecat.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99
import os
10-
from StringIO import StringIO
11-
import numpy as np
1210

13-
import nibabel
11+
import numpy as np
1412

15-
from ..ecat import EcatHeader, EcatMlist, EcatSubHeader, EcatImage, native_code
13+
from ..volumeutils import native_code, swapped_code
14+
from ..ecat import EcatHeader, EcatMlist, EcatSubHeader, EcatImage
1615

1716
from unittest import TestCase
1817

@@ -21,8 +20,9 @@
2120

2221
from numpy.testing import assert_array_equal, assert_array_almost_equal
2322

24-
data_path = os.path.dirname(nibabel.__file__)
25-
ecat_file = os.path.join(data_path, 'tests','data','tinypet.v')
23+
from ..testing import data_path
24+
25+
ecat_file = os.path.join(data_path, 'tinypet.v')
2626

2727
class TestEcatHeader(TestCase):
2828
header_class = EcatHeader
@@ -67,15 +67,21 @@ def test_update(self):
6767
assert_true(hdr['num_frames'] == 0)
6868
hdr['num_frames'] = 2
6969
assert_true(hdr['num_frames'] == 2)
70-
70+
7171
def test_endianness(self):
72-
fid = open(ecat_file)
72+
# Default constructed header should be native
7373
native_hdr = self.header_class()
74+
assert_true(native_hdr.endianness == native_code)
75+
# Swapped constructed header should be swapped
76+
swapped_hdr = self.header_class(endianness=swapped_code)
77+
assert_true(swapped_hdr.endianness == swapped_code)
78+
# Example header is big-endian
79+
fid = open(ecat_file)
7480
file_hdr = native_hdr.from_fileobj(fid)
7581
fid.close()
76-
assert_true(native_hdr.endianness == native_code)
7782
assert_true(file_hdr.endianness == '>')
78-
83+
84+
7985
class TestEcatMlist(TestCase):
8086
header_class = EcatHeader
8187
mlist_class = EcatMlist

0 commit comments

Comments
 (0)