Skip to content

Commit

Permalink
Add test for MapScript point.draw method (#5964)
Browse files Browse the repository at this point in the history
* 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 authored Jan 16, 2020
1 parent 9f6b5ba commit b97cf48
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
12 changes: 2 additions & 10 deletions mapscript/python/tests/cases/image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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"""
Expand All @@ -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"""
Expand All @@ -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__':
Expand Down
55 changes: 55 additions & 0 deletions mapscript/python/tests/cases/point_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion mapscript/python/tests/cases/refcount_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b97cf48

Please sign in to comment.