Skip to content
Permalink
Browse files
Add test for MapScript point.draw method (#5964)
* Add test for point.draw. See #5952

* Use True/False for flags

* Remove redundant code paths

* Remove all assert True from tests
  • Loading branch information
geographika committed Jan 16, 2020
1 parent 9f6b5ba commit b97cf48034f75b2da9debd869f3caad382b71ef4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
@@ -32,11 +32,11 @@
from .testing import MapTestCase


have_image = 0
have_image = False

try:
from PIL import Image
have_image = 1
have_image = True
except ImportError:
pass

@@ -56,8 +56,6 @@ def testSaveToString(self):
assert pyimg.format == 'PNG'
assert pyimg.size == (200, 200)
assert pyimg.mode == 'RGB'
else:
assert 1


class ImageObjTestCase(unittest.TestCase):
@@ -139,8 +137,6 @@ def testImageWrite(self):
assert pyimg.format == 'PNG'
assert pyimg.size == (200, 200)
assert pyimg.mode == 'RGB'
else:
assert 1

def testImageWriteBytesIO(self):
"""image writes data to a BytesIO instance"""
@@ -158,8 +154,6 @@ def testImageWriteBytesIO(self):
assert pyimg.format == 'PNG'
assert pyimg.size == (200, 200)
assert pyimg.mode == 'RGB'
else:
assert 1

def testImageGetBytes(self):
"""image returns bytes"""
@@ -176,8 +170,6 @@ def testImageGetBytes(self):
assert pyimg.format == 'PNG'
assert pyimg.size == (200, 200)
assert pyimg.mode == 'RGB'
else:
assert 1


if __name__ == '__main__':
@@ -28,6 +28,15 @@
import mapscript


have_image = False

try:
from PIL import Image
have_image = True
except ImportError:
pass


class PointObjTestCase(unittest.TestCase):

def testPointObjConstructorNoArgs(self):
@@ -70,6 +79,52 @@ def testSetXYZ(self):
self.assertAlmostEqual(p.z, 3.0)
self.assertAlmostEqual(p.m, 4.0)

def testPointDraw(self):
"""Can create a point, add to a layer, and draw it directly"""

map_string = """
MAP
EXTENT 0 0 90 90
SIZE 500 500
SYMBOL
NAME "circle"
TYPE ELLIPSE
POINTS 1 1 END
FILLED true
END
LAYER
NAME "punkt"
STATUS ON
TYPE POINT
END
END"""

test_map = mapscript.fromstring(map_string)
layer = test_map.getLayerByName('punkt')
cls = mapscript.classObj()
style = mapscript.styleObj()
style.outlinecolor.setHex('#00aa00ff')
style.size = 10
style.setSymbolByName(test_map, 'circle')

cls.insertStyle(style)
class_idx = layer.insertClass(cls)
point = mapscript.pointObj(45, 45)

img = test_map.prepareImage()
point.draw(test_map, layer, img, class_idx, "test")

filename = 'testDrawPoint.png'
with open(filename, 'wb') as fh:
img.write(fh)

if have_image:
pyimg = Image.open(filename)
assert pyimg.size == (500, 500)

def testPoint__str__(self):
"""return properly formatted string"""
p = mapscript.pointObj(1.0, 1.0)
@@ -129,7 +129,6 @@ def testBehaveWhenParentIsNull(self):
layer.open()
except Exception:
# must fail because the new layer is missing information
assert True
exception = True
assert exception is True

0 comments on commit b97cf48

Please sign in to comment.