Permalink
Browse files

Fix Python3 syntax issues in Python tests

  • Loading branch information...
claudep committed Mar 23, 2018
1 parent 89b99a4 commit 968c41486c4651508b5e571d6400e24e8b0a53d3
Showing with 170 additions and 203 deletions.
  1. +3 −3 mapscript/python/pymodule.i
  2. +1 −1 mapscript/python/tests/cases/classtest.py
  3. +3 −4 mapscript/python/tests/cases/clonetest.py
  4. +1 −2 mapscript/python/tests/cases/colortest.py
  5. +1 −1 mapscript/python/tests/cases/fonttest.py
  6. +1 −1 mapscript/python/tests/cases/hashtest.py
  7. +17 −24 mapscript/python/tests/cases/imagetest.py
  8. +1 −1 mapscript/python/tests/cases/labeltest.py
  9. +2 −2 mapscript/python/tests/cases/layertest.py
  10. +1 −2 mapscript/python/tests/cases/linetest.py
  11. +5 −5 mapscript/python/tests/cases/maptest.py
  12. +1 −2 mapscript/python/tests/cases/outputformattest.py
  13. +1 −2 mapscript/python/tests/cases/owstest.py
  14. +1 −1 mapscript/python/tests/cases/parentreference.py
  15. +1 −2 mapscript/python/tests/cases/pgtest.py
  16. +2 −3 mapscript/python/tests/cases/pointtest.py
  17. +3 −3 mapscript/python/tests/cases/recttest.py
  18. +1 −1 mapscript/python/tests/cases/refcount.py
  19. +1 −2 mapscript/python/tests/cases/resultcachetest.py
  20. +1 −1 mapscript/python/tests/cases/shapefiletest.py
  21. +2 −3 mapscript/python/tests/cases/shapetest.py
  22. +1 −1 mapscript/python/tests/cases/styletest.py
  23. +1 −1 mapscript/python/tests/cases/symbolsettest.py
  24. +7 −9 mapscript/python/tests/cases/symboltest.py
  25. +2 −9 mapscript/python/tests/cases/testing.py
  26. +2 −2 mapscript/python/tests/cases/threadtest.py
  27. +1 −1 mapscript/python/tests/cases/zoomtest.py
  28. +1 −1 mapscript/python/tests/runalldoctests.py
  29. +35 −35 mapscript/python/tests/runtests.py
  30. +9 −10 mapscript/python/tests/timing/clonemaps.py
  31. +8 −8 mapscript/python/tests/timing/drawshapes.py
  32. +1 −1 mapscript/python/tests/timing/testing.py
  33. +5 −7 msautotest/mspython/bug_check.py
  34. +4 −4 msautotest/mspython/ogr_query.py
  35. +2 −2 msautotest/mspython/rqtest.py
  36. +3 −5 msautotest/mspython/test_mapio.py
  37. +3 −4 msautotest/mspython/test_xmp.py
  38. +13 −13 msautotest/mspython/wkt.py
  39. +2 −3 msautotest/pymod/mstestlib.py
  40. +20 −21 msautotest/pymod/pmstestlib.py
@@ -109,13 +109,13 @@ CreateTupleFromDoubleArray( double *first, unsigned int size ) {
const char* val = msLookupHashTable(hashTable, key);
if( val )
{
#if PY_VERSION_HEX >= 0x03000000
%#if PY_VERSION_HEX >= 0x03000000
PyObject *py_key = PyUnicode_FromString(key);
PyObject *py_val = PyUnicode_FromString(val);
#else
%#else
PyObject *py_key = PyString_FromString(key);
PyObject *py_val = PyString_FromString(val);
#endif
%#endif
PyDict_SetItem($result, py_key, py_val );
Py_DECREF(py_key);
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase
from .testing import mapscript, MapTestCase
# ===========================================================================
# Test begins now
@@ -37,14 +37,13 @@
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import TESTMAPFILE
from testing import MapscriptTestCase
from .testing import mapscript
from .testing import TESTMAPFILE
# ===========================================================================
# Base class
class MapCloneTestCase(MapscriptTestCase):
class MapCloneTestCase(unittest.TestCase):
"""Base class for testing with a map fixture"""
def setUp(self):
@@ -36,8 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapPrimitivesTestCase
from .testing import MapPrimitivesTestCase, mapscript
# ===========================================================================
# Test begins now
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, TESTMAPFILE, TESTS_PATH
from .testing import mapscript, TESTMAPFILE, TESTS_PATH
class FontTestCase(unittest.TestCase):
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase
from .testing import mapscript, MapTestCase
# ===========================================================================
# Base class for hashtable tests. Derived classes use these tests, but
@@ -34,15 +34,11 @@
import os, sys
import unittest
from io import BytesIO
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import TEST_IMAGE as test_image
from testing import TESTMAPFILE
from testing import MapTestCase
from StringIO import StringIO
import cStringIO
from .testing import TESTMAPFILE, TEST_IMAGE as test_image, mapscript
from .testing import MapTestCase
import urllib
@@ -115,12 +111,11 @@ def xtestConstructorStream(self):
assert imgobj.height == 200
assert imgobj.width == 200
def xtestConstructorStringIO(self):
"""imageObj with a cStringIO works"""
f = open(test_image, 'rb')
data = f.read()
f.close()
s = cStringIO.StringIO(data)
def xtestConstructorBytesIO(self):
"""imageObj with a BytesIO works"""
with open(test_image, 'rb') as f:
data = f.read()
s = BytesIO(data)
imgobj = mapscript.imageObj(s)
assert imgobj.thisown == 1
assert imgobj.height == 200
@@ -153,18 +148,17 @@ def testImageWrite(self):
else:
assert 1
def testImageWriteStringIO(self):
"""image writes data to a StringIO instance"""
def testImageWriteBytesIO(self):
"""image writes data to a BytesIO instance"""
image = self.map.draw()
assert image.thisown == 1
s = cStringIO.StringIO()
s = BytesIO()
image.write(s)
filename = 'testImageWriteStringIO.png'
fh = open(filename, 'wb')
fh.write(s.getvalue())
fh.close()
filename = 'testImageWriteBytesIO.png'
with open(filename, 'wb') as fh:
fh.write(s.getvalue())
if have_image:
pyimg = Image.open(filename)
assert pyimg.format == 'PNG'
@@ -178,12 +172,11 @@ def testImageGetBytes(self):
image = self.map.draw()
assert image.thisown == 1
s = cStringIO.StringIO(image.getBytes())
s = BytesIO(image.getBytes())
filename = 'testImageGetBytes.png'
fh = open(filename, 'wb')
fh.write(s.getvalue())
fh.close()
with open(filename, 'wb') as fh:
fh.write(s.getvalue())
if have_image:
pyimg = Image.open(filename)
assert pyimg.format == 'PNG'
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase
from .testing import mapscript, MapTestCase
# ===========================================================================
# Test begins now
@@ -36,8 +36,8 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapTestCase
from .testing import mapscript
from .testing import MapTestCase
# Base class
class MapLayerTestCase(MapTestCase):
@@ -36,8 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapPrimitivesTestCase
from .testing import MapPrimitivesTestCase, mapscript
class LineObjTestCase(MapPrimitivesTestCase):
"""Testing the lineObj class in stand-alone mode"""
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase, TESTMAPFILE
from .testing import mapscript, MapTestCase, TESTMAPFILE
# ===========================================================================
# Test begins now
@@ -96,9 +96,9 @@ def testMapInsertLayer(self):
n = self.map.numlayers
layer = mapscript.layerObj()
layer.name = 'new'
assert layer.map == None, layer.map
assert layer.map == None, layer.map
index = self.map.insertLayer(layer)
assert layer.map != None, layer.map
assert layer.map != None, layer.map
assert index == n, index
assert self.map.numlayers == n + 1
names = [self.map.getLayer(i).name for i in range(self.map.numlayers)]
@@ -112,9 +112,9 @@ def testMapInsertLayerAtZero(self):
n = self.map.numlayers
layer = mapscript.layerObj()
layer.name = 'new'
assert layer.map == None, layer.map
assert layer.map == None, layer.map
index = self.map.insertLayer(layer, 0)
assert layer.map != None, layer.map
assert layer.map != None, layer.map
assert index == 0, index
assert self.map.numlayers == n + 1
names = [self.map.getLayer(i).name for i in range(self.map.numlayers)]
@@ -36,8 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapTestCase
from .testing import MapTestCase, mapscript
# ===========================================================================
# Test begins now
@@ -36,8 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapTestCase
from .testing import MapTestCase, mapscript
# ===========================================================================
# Test begins now
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase, TESTMAPFILE
from .testing import mapscript, MapTestCase, TESTMAPFILE
# ===========================================================================
# Test begins now
@@ -44,8 +44,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapTestCase
from .testing import MapTestCase, mapscript
PG_CONNECTION_STRING="dbname=mapserver_test user=postgres"
@@ -36,10 +36,9 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapscriptTestCase
from .testing import mapscript
class PointObjTestCase(MapscriptTestCase):
class PointObjTestCase(unittest.TestCase):
def testPointObjConstructorNoArgs(self):
"""point can be created with no arguments"""
@@ -36,8 +36,8 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapPrimitivesTestCase
from .testing import mapscript
from .testing import MapPrimitivesTestCase
# ===========================================================================
# Test begins now
@@ -85,7 +85,7 @@ def testExceptionMessage(self):
"""test formatted error message"""
try:
r = mapscript.rectObj(1.0, -2.0, -3.0, 4.0)
except mapscript.MapServerError, msg:
except mapscript.MapServerError as msg:
assert str(msg) == "rectObj(): Invalid rectangle. { 'minx': 1.000000 , 'miny': -2.000000 , 'maxx': -3.000000 , 'maxy': 4.000000 }", msg
def testRect__str__(self):
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase, TESTMAPFILE
from .testing import mapscript, MapTestCase, TESTMAPFILE
# ===========================================================================
# Test begins now
@@ -36,8 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript
from testing import MapTestCase, MapPrimitivesTestCase
from .testing import MapTestCase, MapPrimitivesTestCase, mapscript
# Base class
class LayerQueryTestCase(MapTestCase):
@@ -36,7 +36,7 @@
import os
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, TESTS_PATH
from .testing import mapscript, TESTS_PATH
class AddShapeTestCase(unittest.TestCase):
@@ -36,9 +36,8 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase
from testing import MapPrimitivesTestCase, ShapeObjTestCase
from testing import MapscriptTestCase
from .testing import mapscript, MapTestCase
from .testing import MapPrimitivesTestCase, ShapeObjTestCase
class ShapePointTestCase(ShapeObjTestCase):
"""Test point type shapeObj in stand-alone mode"""
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase
from .testing import mapscript, MapTestCase
class DrawProgrammedStylesTestCase(MapTestCase):
def testDrawPoints(self):
@@ -36,7 +36,7 @@
import unittest
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase, TESTMAPFILE, XMARKS_IMAGE, TESTS_PATH
from .testing import mapscript, MapTestCase, TESTMAPFILE, XMARKS_IMAGE, TESTS_PATH
SYMBOLSET = os.path.join(TESTS_PATH, "symbols.txt")
@@ -34,11 +34,11 @@
import os, sys
import unittest
import StringIO
from io import BytesIO
# the testing module helps us import the pre-installed mapscript
from testing import mapscript, MapTestCase
from testing import TESTMAPFILE, XMARKS_IMAGE, HOME_IMAGE
from .testing import mapscript, MapTestCase
from .testing import TESTMAPFILE, XMARKS_IMAGE, HOME_IMAGE
# ===========================================================================
# Test begins now
@@ -65,16 +65,14 @@ class DynamicGraphicSymbolTestCase():
def setUp(self):
MapTestCase.setUp(self)
f = open(HOME_IMAGE, 'rb')
s = StringIO.StringIO(f.read())
f.close()
with open(HOME_IMAGE, 'rb') as fh:
s = BytesIO(fh.read())
symb_img = mapscript.imageObj(s)
self.h_symbol = mapscript.symbolObj('house')
self.h_symbol.type = mapscript.MS_SYMBOL_PIXMAP
self.h_symbol.setImage(symb_img)
f = open(XMARKS_IMAGE, 'rb')
s = StringIO.StringIO(f.read())
f.close()
with open(XMARKS_IMAGE, 'rb') as fh:
s = BytesIO(fh.read())
symb_img = mapscript.imageObj(s)
self.x_symbol = mapscript.symbolObj('xmarks')
self.x_symbol.type = mapscript.MS_SYMBOL_PIXMAP
Oops, something went wrong.

0 comments on commit 968c414

Please sign in to comment.