File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1224,6 +1224,32 @@ def test_ext_eq():
1224
1224
assert not ext == ext2
1225
1225
1226
1226
1227
+ def test_extension_content_access ():
1228
+ ext = Nifti1Extension ('comment' , b'123' )
1229
+ # Unmangled content access
1230
+ assert ext .get_content () == b'123'
1231
+
1232
+ # Raw, text and JSON access
1233
+ assert ext .content == b'123'
1234
+ assert ext .text == '123'
1235
+ assert ext .json () == 123
1236
+
1237
+ # Encoding can be set
1238
+ ext .encoding = 'ascii'
1239
+ assert ext .text == '123'
1240
+
1241
+ # Test that encoding errors are caught
1242
+ ascii_ext = Nifti1Extension ('comment' , 'hôpital' .encode ('utf-8' ))
1243
+ ascii_ext .encoding = 'ascii'
1244
+ with pytest .raises (UnicodeDecodeError ):
1245
+ ascii_ext .text
1246
+
1247
+ json_ext = Nifti1Extension ('unknown' , b'{"a": 1}' )
1248
+ assert json_ext .content == b'{"a": 1}'
1249
+ assert json_ext .text == '{"a": 1}'
1250
+ assert json_ext .json () == {'a' : 1 }
1251
+
1252
+
1227
1253
def test_extension_codes ():
1228
1254
for k in extension_codes .keys ():
1229
1255
Nifti1Extension (k , 'somevalue' )
You can’t perform that action at this time.
0 commit comments