Skip to content

Commit 2ad5621

Browse files
matthew-bretteffigies
authored andcommitted
BF: isolate ImageOpener extension list
ImageOpener extension list was pointer to dictionary from Opener class, so modifying ImageOpener modified Opener.
1 parent fce4cad commit 2ad5621

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

nibabel/openers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class ImageOpener(Opener):
155155
attributes, via the `register_ex_from_images`. The class can therefore
156156
change state when image classes are defined.
157157
"""
158+
compress_ext_map = Opener.compress_ext_map.copy()
158159

159160
@classmethod
160161
def register_ext_from_image(opener_klass, ext, func_def):

nibabel/tests/test_openers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_Opener():
5757
# mode is gently ignored
5858
fobj = Opener(obj, mode='r')
5959

60+
6061
def test_Opener_various():
6162
# Check we can do all sorts of files here
6263
message = b"Oh what a giveaway"
@@ -84,11 +85,13 @@ def test_Opener_various():
8485
# Just check there is a fileno
8586
assert_not_equal(fobj.fileno(), 0)
8687

88+
8789
def test_BinOpener():
8890
with error_warnings():
8991
assert_raises(DeprecationWarning,
9092
BinOpener, 'test.txt', 'r')
9193

94+
9295
class TestImageOpener:
9396
alternate_exts = ()
9497
def setUp(self):
@@ -123,6 +126,9 @@ def file_opener(fileish, mode):
123126
pass
124127
assert_true(os.path.exists('test.foo'))
125128

129+
# Check this doesn't add anything to parent
130+
assert_false('.foo' in Opener.compress_ext_map)
131+
126132

127133
def test_file_like_wrapper():
128134
# Test wrapper using BytesIO (full API)

0 commit comments

Comments
 (0)