Commit 90707b32 authored by Ian Lee's avatar Ian Lee

Added test coverage for Overlay class

parent e1e174cf
......@@ -28,6 +28,7 @@ http://schemas.opengis.net/kml/.
try:
import urlparse
except ImportError:
# Python 3
import urllib.parse as urlparse
import warnings
......@@ -650,19 +651,15 @@ class _Overlay(_Feature):
Base type for image overlays drawn on the planet surface or on the screen
A Container element holds one or more Features and allows the
creation of nested hierarchies.
subclasses are:
* GroundOverlay
* PhotoOverlay
* ScreenOverlay
A Container element holds one or more Features and allows the creation of
nested hierarchies.
"""
_color = None
# Color values expressed in hexadecimal notation, including opacity (alpha)
# values. The order of expression is alpha, blue, green, red (AABBGGRR).
# The range of values for any one color is 0 to 255 (00 to ff). For
# opacity, 00 is fully transparent and ff is fully opaque.
# values. The order of expression is alpOverlayha, blue, green, red
# (AABBGGRR). The range of values for any one color is 0 to 255 (00 to ff).
# For opacity, 00 is fully transparent and ff is fully opaque.
_drawOrder = None
# Defines the stacking order for the images in overlapping overlays.
......@@ -703,7 +700,7 @@ class _Overlay(_Feature):
except (ValueError, TypeError):
self._drawOrder = None
else:
self._drawOrder = value
self._drawOrder = str(value)
@property
def icon(self):
......@@ -722,6 +719,31 @@ class _Overlay(_Feature):
else:
raise ValueError
def etree_element(self):
element = super(_Overlay, self).etree_element()
if self._color:
color = etree.SubElement(element, "%scolor" % self.ns)
color.text = self._color
if self._drawOrder:
drawOrder = etree.SubElement(element, "%sdrawOrder" % self.ns)
drawOrder.text = self._drawOrder
if self._icon:
icon = etree.SubElement(element, "%sicon" % self.ns)
icon.text = self._icon
return element
class GroundOverlay(_Overlay):
"""
This element draws an image overlay draped onto the terrain. The <href>
child of <Icon> specifies the image to be used as the overlay. This file
can be either on a local file system or on a web server. If this element is
omitted or contains no <href>, a rectangle is drawn using the color and
LatLonBox bounds defined by the ground overlay.
"""
__name__ = 'GroundOverlay'
class Document(_Container):
"""
......
......@@ -22,6 +22,7 @@ from fastkml import styles
from fastkml import base
from fastkml import atom
from fastkml import config
from fastkml import gx
import datetime
from dateutil.tz import tzutc, tzoffset
......@@ -115,6 +116,17 @@ class BaseClassesTestCase(unittest.TestCase):
self.assertEqual(o._color, None)
self.assertEqual(o._drawOrder, None)
self.assertEqual(o._icon, None)
self.assertRaises(NotImplementedError, o.etree_element)
def test_atom_link(self):
ns = '{http://www.opengis.net/kml/2.2}'
l = atom.Link(ns=ns)
self.assertEqual(l.ns, ns)
def test_atom_person(self):
ns = '{http://www.opengis.net/kml/2.2}'
p = atom._Person(ns=ns)
self.assertEqual(p.ns, ns)
class BuildKmlTestCase(unittest.TestCase):
......@@ -1939,6 +1951,21 @@ class Force3DTestCase(unittest.TestCase):
class BaseOverlayTestCase(unittest.TestCase):
def test_color(self):
o = kml._Overlay(name='An Overlay')
o.color = '00010203'
self.assertEqual(o.color, '00010203')
def test_draw_order_string(self):
o = kml._Overlay(name='An Overlay')
o.drawOrder = '1'
self.assertEqual(o.drawOrder, '1')
def test_draw_order_int(self):
o = kml._Overlay(name='An Overlay')
o.drawOrder = 1
self.assertEqual(o.drawOrder, '1')
def test_icon_without_tag(self):
o = kml._Overlay(name='An Overlay')
o.icon = 'http://example.com/'
......@@ -1972,6 +1999,34 @@ class BaseOverlayTestCase(unittest.TestCase):
o.icon = 12345
class GroundOverlayTestCase(unittest.TestCase):
def test_default_to_string(self):
g = kml.GroundOverlay()
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_to_string(self):
g = kml.GroundOverlay()
g.icon = 'http://example.com'
g.drawOrder = 1
g.color = '00010203'
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:color>00010203</kml:color>'
'<kml:drawOrder>1</kml:drawOrder>'
'<kml:icon>&lt;href&gt;http://example.com&lt;/href&gt;</kml:icon>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(BaseClassesTestCase))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment