@@ -212,7 +212,7 @@ def test_annot():
212
212
213
213
214
214
def test_read_write_annot ():
215
- """Test generating .annot fiole and reading it back."""
215
+ """Test generating .annot file and reading it back."""
216
216
# This annot file will store a LUT for a mesh made of 10 vertices, with
217
217
# 3 colours in the LUT.
218
218
nvertices = 10
@@ -242,6 +242,7 @@ def test_read_write_annot():
242
242
with InTemporaryDirectory ():
243
243
write_annot (annot_path , labels , rgbal , names , fill_ctab = False )
244
244
labels2 , rgbal2 , names2 = read_annot (annot_path )
245
+ names2 = [n .decode ('ascii' ) for n in names2 ]
245
246
assert np .all (np .isclose (rgbal2 , rgbal ))
246
247
assert np .all (np .isclose (labels2 , labels ))
247
248
assert names2 == names
@@ -261,6 +262,7 @@ def test_write_annot_fill_ctab():
261
262
with InTemporaryDirectory ():
262
263
write_annot (annot_path , labels , rgba , names , fill_ctab = True )
263
264
labels2 , rgbal2 , names2 = read_annot (annot_path )
265
+ names2 = [n .decode ('ascii' ) for n in names2 ]
264
266
assert np .all (np .isclose (rgbal2 [:, :4 ], rgba ))
265
267
assert np .all (np .isclose (labels2 , labels ))
266
268
assert names2 == names
@@ -276,6 +278,7 @@ def test_write_annot_fill_ctab():
276
278
any ('Annotation values in {} will be incorrect' .format (
277
279
annot_path ) == str (ww .message ) for ww in w ))
278
280
labels2 , rgbal2 , names2 = read_annot (annot_path , orig_ids = True )
281
+ names2 = [n .decode ('ascii' ) for n in names2 ]
279
282
assert np .all (np .isclose (rgbal2 [:, :4 ], rgba ))
280
283
assert np .all (np .isclose (labels2 , badannot [labels ].squeeze ()))
281
284
assert names2 == names
@@ -292,6 +295,7 @@ def test_write_annot_fill_ctab():
292
295
not any ('Annotation values in {} will be incorrect' .format (
293
296
annot_path ) == str (ww .message ) for ww in w ))
294
297
labels2 , rgbal2 , names2 = read_annot (annot_path )
298
+ names2 = [n .decode ('ascii' ) for n in names2 ]
295
299
assert np .all (np .isclose (rgbal2 [:, :4 ], rgba ))
296
300
assert np .all (np .isclose (labels2 , labels ))
297
301
assert names2 == names
@@ -315,11 +319,11 @@ def gen_old_annot_file(fpath, nverts, labels, rgba, names):
315
319
fbytes += struct .pack (dt , rgba .shape [0 ])
316
320
# length of orig_tab string
317
321
fbytes += struct .pack (dt , 5 )
318
- fbytes += b'abcd\00 '
322
+ fbytes += b'abcd\x00 '
319
323
for i in range (rgba .shape [0 ]):
320
324
# length of entry name (+1 for terminating byte)
321
325
fbytes += struct .pack (dt , len (names [i ]) + 1 )
322
- fbytes += names [i ].encode ('ascii' ) + b'\00 '
326
+ fbytes += names [i ].encode ('ascii' ) + b'\x00 '
323
327
fbytes += bytes (rgba [i , :].astype (dt ).tostring ())
324
328
with open (fpath , 'wb' ) as f :
325
329
f .write (fbytes )
@@ -335,6 +339,7 @@ def gen_old_annot_file(fpath, nverts, labels, rgba, names):
335
339
gen_old_annot_file ('blah.annot' , nverts , labels , rgba , names )
336
340
# read it back
337
341
rlabels , rrgba , rnames = read_annot ('blah.annot' )
342
+ rnames = [n .decode ('ascii' ) for n in rnames ]
338
343
assert np .all (np .isclose (labels , rlabels ))
339
344
assert np .all (np .isclose (rgba , rrgba [:, :4 ]))
340
345
assert names == rnames
0 commit comments