Merge pull request #229 from wiredfool/warnings

Fixing and Suppressing warnings revealed in #227
This commit is contained in:
wiredfool 2013-05-24 08:36:57 -07:00
commit aad417dcbe
3 changed files with 20 additions and 2 deletions

View File

@ -47,7 +47,11 @@ class ImagePalette:
raise ValueError("palette contains raw palette data")
if isinstance(self.palette, bytes):
return self.palette
return array.array("B", self.palette).tostring()
arr = array.array("B", self.palette)
if hasattr(arr, 'tobytes'):
#py3k has a tobytes, tostring is deprecated.
return arr.tobytes()
return arr.tostring()
# Declare tostring as an alias for tobytes
tostring = tobytes

View File

@ -45,5 +45,10 @@ def test_path():
assert_equal(list(p), [(0.0, 1.0)])
p = ImagePath.Path(array.array("f", [0, 1]))
assert_equal(list(p), [(0.0, 1.0)])
p = ImagePath.Path(array.array("f", [0, 1]).tostring())
arr = array.array("f", [0, 1])
if hasattr(arr, 'tobytes'):
p = ImagePath.Path(arr.tobytes())
else:
p = ImagePath.Path(arr.tostring())
assert_equal(list(p), [(0.0, 1.0)])

View File

@ -3,6 +3,15 @@ from __future__ import print_function
# require that deprecation warnings are triggered
import warnings
warnings.simplefilter('default')
# temporarily turn off resource warnings that warn about unclosed
# files in the test scripts.
try:
warnings.filterwarnings("ignore", category=ResourceWarning)
except NameError:
# we expect a NameError on py2.x, since it doesn't have ResourceWarnings.
pass
import sys
py3 = (sys.version_info >= (3,0))