|
9 | 9 |
|
10 | 10 | from nibabel.tests.test_image_api import GenericImageAPI
|
11 | 11 |
|
| 12 | +from nose.tools import (assert_true, assert_false, assert_equal, |
| 13 | + assert_not_equal) |
| 14 | + |
12 | 15 |
|
13 | 16 | class FBNumpyImage(FileBasedImage):
|
14 | 17 | header_class = FileBasedHeader
|
@@ -72,3 +75,35 @@ def make_imaker(arr, header=None):
|
72 | 75 | shape=shape,
|
73 | 76 | is_proxy=False)
|
74 | 77 | 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