Skip to content
Snippets Groups Projects
Commit c7d7de28 authored by David Gobbi's avatar David Gobbi
Browse files

Add a few other minor py3k test fixes.

1) Change unicode string unicode string check in TestTemplates.py.
2) Eliminate some obsolete imports (like "exceptions").
3) Convert string to bytes in TestDataEncoder.py.
parent ae48313c
Branches
Tags
No related merge requests found
......@@ -29,6 +29,12 @@ arrayCodes = ['c', 'b', 'B', 'h', 'H',
'i', 'I', 'l', 'L', 'q', 'Q',
'f', 'd']
# create a unicode string for python 2 and python 3
if sys.hexversion >= 0x03000000:
francois = 'Fran\xe7ois'
else:
francois = unicode('Fran\xe7ois', 'latin1')
class TestTemplates(Testing.vtkTest):
def testDenseArray(self):
......@@ -52,8 +58,13 @@ class TestTemplates(Testing.vtkTest):
a.SetValue(i, value)
result = a.GetValue(i)
self.assertEqual(value, result)
elif t in [str, 'str', 'unicode']:
value = u"hello"
elif t in [str, 'str']:
value = "hello"
a.SetValue(i, value)
result = a.GetValue(i)
self.assertEqual(value, result)
elif t in ['unicode']:
value = francois
a.SetValue(i, value)
result = a.GetValue(i)
self.assertEqual(value, result)
......@@ -89,8 +100,13 @@ class TestTemplates(Testing.vtkTest):
a.SetValue(i, value)
result = a.GetValue(i)
self.assertEqual(value, result)
elif t in [str, 'str', 'unicode']:
value = u"hello"
elif t in [str, 'str']:
value = "hello"
a.SetValue(i, value)
result = a.GetValue(i)
self.assertEqual(value, result)
elif t in ['unicode']:
value = francois
a.SetValue(i, value)
result = a.GetValue(i)
self.assertEqual(value, result)
......
import sys
try:
# for Python2
import exceptions
except ImportError:
# In Python 3 standard exceptions were moved to builtin module.
pass
import vtk
from vtk.test import Testing
......
......@@ -32,7 +32,6 @@ import sys
import re
import os
import stat
import string
# Get the path to the directory containing this script.
if __name__ == '__main__':
......@@ -115,11 +114,15 @@ class TestVTKFiles:
self.ClassName = ""
self.ParentName = ""
try:
file = open(filename)
if sys.hexversion >= 0x03000000:
file = open(filename, encoding='ascii', errors='ignore')
else:
file = open(filename)
self.FileLines = file.readlines()
file.close()
except:
self.Print( "Problem reading file: %s" % filename )
self.Print("Problem reading file %s:\n%s" %
(filename, str(sys.exc_info()[1])))
sys.exit(1)
return not self.CheckExclude()
......
import sys
try:
# for Python2
import exceptions
except ImportError:
# for Python3
pass
import vtk
import array
from vtk.test import Testing
......@@ -43,7 +37,7 @@ class TestDataEncoder(Testing.vtkTest):
# Use vtkDataEncoder to convert the image to PNG format and Base64 encode it
encoder = vtk.vtkDataEncoder()
base64String = encoder.EncodeAsBase64Png(imgData)
base64String = encoder.EncodeAsBase64Png(imgData).encode('ascii')
# Now Base64 decode the string back to PNG image data bytes
outputBuffer = bytearray(120000)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment