Skip to content

Commit 2dffa52

Browse files
matthew-bretteffigies
authored andcommitted
TST: add tests for FileBasedHeader objects
Test that copy produces an independent copy, and that from_header produces a copy, or an empty header.
1 parent 42501a5 commit 2dffa52

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

nibabel/tests/test_filebasedimages.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
from nibabel.tests.test_image_api import GenericImageAPI
1111

12+
from nose.tools import (assert_true, assert_false, assert_equal,
13+
assert_not_equal)
14+
1215

1316
class FBNumpyImage(FileBasedImage):
1417
header_class = FileBasedHeader
@@ -72,3 +75,35 @@ def make_imaker(arr, header=None):
7275
shape=shape,
7376
is_proxy=False)
7477
yield func, params
78+
79+
80+
def test_filebased_header():
81+
# Test stuff about the default FileBasedHeader
82+
83+
class H(FileBasedHeader):
84+
85+
def __init__(self, seq=None):
86+
if seq is None:
87+
seq = []
88+
self.a_list = list(seq)
89+
90+
in_list = [1, 3, 2]
91+
hdr = H(in_list)
92+
hdr_c = hdr.copy()
93+
assert_equal(hdr_c.a_list, hdr.a_list)
94+
# Copy is independent of original
95+
hdr_c.a_list[0] = 99
96+
assert_not_equal(hdr_c.a_list, hdr.a_list)
97+
# From header does a copy
98+
hdr2 = H.from_header(hdr)
99+
assert_true(isinstance(hdr2, H))
100+
assert_equal(hdr2.a_list, hdr.a_list)
101+
hdr2.a_list[0] = 42
102+
assert_not_equal(hdr2.a_list, hdr.a_list)
103+
# Default header input to from_heder gives new empty header
104+
hdr3 = H.from_header()
105+
assert_true(isinstance(hdr3, H))
106+
assert_equal(hdr3.a_list, [])
107+
hdr4 = H.from_header(None)
108+
assert_true(isinstance(hdr4, H))
109+
assert_equal(hdr4.a_list, [])

0 commit comments

Comments
 (0)