@@ -212,7 +212,7 @@ def test_annot():
212212
213213
214214def test_read_write_annot ():
215- """Test generating .annot fiole and reading it back."""
215+ """Test generating .annot file and reading it back."""
216216 # This annot file will store a LUT for a mesh made of 10 vertices, with
217217 # 3 colours in the LUT.
218218 nvertices = 10
@@ -242,6 +242,7 @@ def test_read_write_annot():
242242 with InTemporaryDirectory ():
243243 write_annot (annot_path , labels , rgbal , names , fill_ctab = False )
244244 labels2 , rgbal2 , names2 = read_annot (annot_path )
245+ names2 = [n .decode ('ascii' ) for n in names2 ]
245246 assert np .all (np .isclose (rgbal2 , rgbal ))
246247 assert np .all (np .isclose (labels2 , labels ))
247248 assert names2 == names
@@ -261,6 +262,7 @@ def test_write_annot_fill_ctab():
261262 with InTemporaryDirectory ():
262263 write_annot (annot_path , labels , rgba , names , fill_ctab = True )
263264 labels2 , rgbal2 , names2 = read_annot (annot_path )
265+ names2 = [n .decode ('ascii' ) for n in names2 ]
264266 assert np .all (np .isclose (rgbal2 [:, :4 ], rgba ))
265267 assert np .all (np .isclose (labels2 , labels ))
266268 assert names2 == names
@@ -276,6 +278,7 @@ def test_write_annot_fill_ctab():
276278 any ('Annotation values in {} will be incorrect' .format (
277279 annot_path ) == str (ww .message ) for ww in w ))
278280 labels2 , rgbal2 , names2 = read_annot (annot_path , orig_ids = True )
281+ names2 = [n .decode ('ascii' ) for n in names2 ]
279282 assert np .all (np .isclose (rgbal2 [:, :4 ], rgba ))
280283 assert np .all (np .isclose (labels2 , badannot [labels ].squeeze ()))
281284 assert names2 == names
@@ -292,6 +295,7 @@ def test_write_annot_fill_ctab():
292295 not any ('Annotation values in {} will be incorrect' .format (
293296 annot_path ) == str (ww .message ) for ww in w ))
294297 labels2 , rgbal2 , names2 = read_annot (annot_path )
298+ names2 = [n .decode ('ascii' ) for n in names2 ]
295299 assert np .all (np .isclose (rgbal2 [:, :4 ], rgba ))
296300 assert np .all (np .isclose (labels2 , labels ))
297301 assert names2 == names
@@ -315,11 +319,11 @@ def gen_old_annot_file(fpath, nverts, labels, rgba, names):
315319 fbytes += struct .pack (dt , rgba .shape [0 ])
316320 # length of orig_tab string
317321 fbytes += struct .pack (dt , 5 )
318- fbytes += b'abcd\00 '
322+ fbytes += b'abcd\x00 '
319323 for i in range (rgba .shape [0 ]):
320324 # length of entry name (+1 for terminating byte)
321325 fbytes += struct .pack (dt , len (names [i ]) + 1 )
322- fbytes += names [i ].encode ('ascii' ) + b'\00 '
326+ fbytes += names [i ].encode ('ascii' ) + b'\x00 '
323327 fbytes += bytes (rgba [i , :].astype (dt ).tostring ())
324328 with open (fpath , 'wb' ) as f :
325329 f .write (fbytes )
@@ -335,6 +339,7 @@ def gen_old_annot_file(fpath, nverts, labels, rgba, names):
335339 gen_old_annot_file ('blah.annot' , nverts , labels , rgba , names )
336340 # read it back
337341 rlabels , rrgba , rnames = read_annot ('blah.annot' )
342+ rnames = [n .decode ('ascii' ) for n in rnames ]
338343 assert np .all (np .isclose (labels , rlabels ))
339344 assert np .all (np .isclose (rgba , rrgba [:, :4 ]))
340345 assert names == rnames
0 commit comments