Skip to content

Commit ff8238f

Browse files
committed
RF - refactored 2 to 3 doctest markup with more comprehensive tests
1 parent b9903f9 commit ff8238f

File tree

8 files changed

+263
-152
lines changed

8 files changed

+263
-152
lines changed

nibabel/analyze.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ def from_fileobj(klass, fileobj, endianness=None, check=True):
395395
396396
Examples
397397
--------
398-
>>> from StringIO import StringIO as BytesIO
398+
>>> from StringIO import StringIO #23dt : BytesIO
399399
>>> hdr = AnalyzeHeader()
400-
>>> fileobj = BytesIO(hdr.binaryblock)
400+
>>> fileobj = StringIO(hdr.binaryblock) #23dt : BytesIO
401401
>>> _ = fileobj.seek(0) # returns 0 in python 3
402402
>>> hdr2 = AnalyzeHeader.from_fileobj(fileobj)
403403
>>> hdr2.binaryblock == hdr.binaryblock
@@ -445,8 +445,8 @@ def write_to(self, fileobj):
445445
Examples
446446
--------
447447
>>> hdr = AnalyzeHeader()
448-
>>> from StringIO import StringIO as BytesIO
449-
>>> str_io = BytesIO()
448+
>>> from StringIO import StringIO #23dt : BytesIO
449+
>>> str_io = StringIO() #23dt : BytesIO
450450
>>> hdr.write_to(str_io)
451451
>>> hdr.binaryblock == str_io.getvalue()
452452
True
@@ -612,8 +612,8 @@ def data_to_fileobj(self, data, fileobj):
612612
>>> hdr = AnalyzeHeader()
613613
>>> hdr.set_data_shape((1, 2, 3))
614614
>>> hdr.set_data_dtype(np.float64)
615-
>>> from StringIO import StringIO as BytesIO
616-
>>> str_io = BytesIO()
615+
>>> from StringIO import StringIO #23dt : BytesIO
616+
>>> str_io = StringIO() #23dt : BytesIO
617617
>>> data = np.arange(6).reshape(1,2,3)
618618
>>> hdr.data_to_fileobj(data, str_io)
619619
>>> data.astype(np.float64).tostring('F') == str_io.getvalue()
@@ -655,7 +655,7 @@ def __setitem__(self, item, value):
655655
--------
656656
>>> hdr = AnalyzeHeader()
657657
>>> hdr['descrip'] = 'description'
658-
>>> np.asscalar(hdr['descrip']) #2to3: next; replace("'d", "b'd")
658+
>>> np.asscalar(hdr['descrip']) #23dt next : bytes
659659
'description'
660660
'''
661661
self._header_data[item] = value

nibabel/externals/netcdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@
117117
To read the NetCDF file we just created:
118118
119119
>>> f = netcdf_file(fname, 'r')
120-
>>> f.history #2to3: next; bytes
120+
>>> f.history #23dt next : bytes
121121
'Created for a test'
122122
>>> time = f.variables['time']
123-
>>> time.units #2to3: next; bytes
123+
>>> time.units #23dt next : bytes
124124
'days since 2008-01-01'
125125
>>> print time.shape
126126
(10,)

nibabel/nicom/structreader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class Unpacker(object):
1414
1515
Examples
1616
--------
17-
>>> a = '1234567890' #2to3: here; bytes
17+
>>> a = '1234567890' #23dt : bytes
1818
>>> upk = Unpacker(a)
19-
>>> upk.unpack('2s') #2to3: next; bytes
19+
>>> upk.unpack('2s') #23dt next : bytes
2020
('12',)
21-
>>> upk.unpack('2s') #2to3: next; bytes
21+
>>> upk.unpack('2s') #23dt next : bytes
2222
('34',)
2323
>>> upk.ptr
2424
4
25-
>>> upk.read(3) #2to3: next; bytes
25+
>>> upk.read(3) #23dt next : bytes
2626
'567'
2727
>>> upk.ptr
2828
7

nibabel/spatialimages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@
103103
work:
104104
105105
>>> # write an image to files
106-
>>> from StringIO import StringIO as BytesIO
106+
>>> from StringIO import StringIO #23dt : BytesIO
107107
>>> file_map = nib.AnalyzeImage.make_file_map()
108-
>>> file_map['image'].fileobj = BytesIO()
109-
>>> file_map['header'].fileobj = BytesIO()
108+
>>> file_map['image'].fileobj = StringIO() #23dt : BytesIO
109+
>>> file_map['header'].fileobj = StringIO() #23dt : BytesIO
110110
>>> img = nib.AnalyzeImage(data, np.eye(4))
111111
>>> img.file_map = file_map
112112
>>> img.to_file_map()

nibabel/trackvis.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ def write(fileobj, streamlines, hdr_mapping=None, endianness=None):
237237
238238
Examples
239239
--------
240-
>>> from StringIO import StringIO as BytesIO
241-
>>> file_obj = BytesIO()
240+
>>> from StringIO import StringIO #23dt : BytesIO
241+
>>> file_obj = StringIO() #23dt : BytesIO
242242
>>> pts0 = np.random.uniform(size=(10,3))
243243
>>> pts1 = np.random.uniform(size=(10,3))
244244
>>> streamlines = ([(pts0, None, None), (pts1, None, None)])
@@ -251,7 +251,7 @@ def write(fileobj, streamlines, hdr_mapping=None, endianness=None):
251251
If there are too many streamlines to fit in memory, you can pass an iterable
252252
thing instead of a list
253253
254-
>>> file_obj = BytesIO()
254+
>>> file_obj = StringIO() #23dt : BytesIO
255255
>>> def gen():
256256
... yield (pts0, None, None)
257257
... yield (pts0, None, None)
@@ -387,7 +387,7 @@ def empty_header(endianness=None, version=2):
387387
>>> hdr = empty_header()
388388
>>> print hdr['version']
389389
2
390-
>>> np.asscalar(hdr['id_string']) #2to3: next; bytes
390+
>>> np.asscalar(hdr['id_string']) #23dt next : bytes
391391
'TRACK'
392392
>>> endian_codes[hdr['version'].dtype.byteorder] == native_code
393393
True

nibabel/volumeutils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,15 @@ def array_from_file(shape, in_dtype, infile, offset=0, order='F'):
387387
388388
Examples
389389
--------
390-
>>> from StringIO import StringIO as BytesIO
391-
>>> bio = BytesIO()
390+
>>> from StringIO import StringIO #23dt : BytesIO
391+
>>> bio = StringIO() #23dt : BytesIO
392392
>>> arr = np.arange(6).reshape(1,2,3)
393393
>>> _ = bio.write(arr.tostring('F')) # outputs int in python3
394394
>>> arr2 = array_from_file((1,2,3), arr.dtype, bio)
395395
>>> np.all(arr == arr2)
396396
True
397-
>>> bio = BytesIO()
398-
>>> _ = bio.write(' ' * 10) #2to3: here; bytes
397+
>>> bio = StringIO() #23dt : BytesIO
398+
>>> _ = bio.write(' ' * 10) #23dt : bytes
399399
>>> _ = bio.write(arr.tostring('F'))
400400
>>> arr2 = array_from_file((1,2,3), arr.dtype, bio, 10)
401401
>>> np.all(arr == arr2)
@@ -485,8 +485,8 @@ def array_to_file(data, fileobj, out_dtype=None, offset=0,
485485
486486
Examples
487487
--------
488-
>>> from StringIO import StringIO as BytesIO
489-
>>> sio = BytesIO()
488+
>>> from StringIO import StringIO #23dt : BytesIO
489+
>>> sio = StringIO() #23dt : BytesIO
490490
>>> data = np.arange(10, dtype=np.float)
491491
>>> array_to_file(data, sio, np.float)
492492
>>> sio.getvalue() == data.tostring('F')
@@ -869,7 +869,7 @@ def rec2dict(rec):
869869
--------
870870
>>> r = np.zeros((), dtype = [('x', 'i4'), ('s', 'S10')])
871871
>>> d = rec2dict(r)
872-
>>> d == {'x': 0, 's': ''} #2to3: here; replace("''", "b''")
872+
>>> d == {'x': 0, 's': ''} #23dt : replace("''", "b''")
873873
True
874874
'''
875875
dct = {}

0 commit comments

Comments
 (0)