Skip to content

Commit 63c3a2a

Browse files
committed
TEST: Adjust Nifti1Header.set_intent test - different error is being raised
for an invalid code. Add some more tests to make sure unknown intent code is supported.
1 parent 84a873f commit 63c3a2a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

nibabel/tests/test_nifti1.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_intents(self):
562562
assert_equal(ehdr.get_intent(),
563563
('t test', (10.0,), 'some score'))
564564
# invalid intent name
565-
assert_raises(KeyError, ehdr.set_intent, 'no intention')
565+
assert_raises(ValueError, ehdr.set_intent, 'no intention')
566566
# too many parameters
567567
assert_raises(HeaderDataError, ehdr.set_intent, 't test', (10, 10))
568568
# too few parameters
@@ -574,6 +574,13 @@ def test_intents(self):
574574
assert_equal(ehdr['intent_name'], b'')
575575
ehdr.set_intent('t test', (10,))
576576
assert_equal((ehdr['intent_p2'], ehdr['intent_p3']), (0, 0))
577+
# store intent that is not in nifti1.intent_codes recoder
578+
ehdr.set_intent(code=9999)
579+
assert_equal(ehdr.get_intent(), ('', (), ''))
580+
assert_equal(ehdr.get_intent('code'), (9999, (), ''))
581+
ehdr.set_intent(code=9999, name='custom intent')
582+
assert_equal(ehdr.get_intent(), ('', (), 'custom intent'))
583+
assert_equal(ehdr.get_intent('code'), (9999, (), 'custom intent'))
577584

578585
def test_set_slice_times(self):
579586
hdr = self.header_class()

0 commit comments

Comments
 (0)