Commit e1e174cf authored by Ian Lee's avatar Ian Lee

Added implementation of icon setter w/ tests.

parent b7bad6b2
......@@ -711,7 +711,16 @@ class _Overlay(_Feature):
@icon.setter
def icon(self, url):
self._icon = url
if isinstance(url, str):
if not url.startswith('<href>'):
url = '<href>' + url
if not url.endswith('</href>'):
url = url + '</href>'
self._icon = url
elif url is None:
self._icon = None
else:
raise ValueError
class Document(_Container):
......
......@@ -110,6 +110,12 @@ class BaseClassesTestCase(unittest.TestCase):
def test_Person(self):
pass
def test_Overlay(self):
o = kml._Overlay(name='An Overlay')
self.assertEqual(o._color, None)
self.assertEqual(o._drawOrder, None)
self.assertEqual(o._icon, None)
class BuildKmlTestCase(unittest.TestCase):
""" Build a simple KML File """
......@@ -1932,6 +1938,40 @@ class Force3DTestCase(unittest.TestCase):
config.FORCE3D = False
class BaseOverlayTestCase(unittest.TestCase):
def test_icon_without_tag(self):
o = kml._Overlay(name='An Overlay')
o.icon = 'http://example.com/'
self.assertEqual(o.icon, '<href>http://example.com/</href>')
def test_icon_with_open_tag(self):
o = kml._Overlay(name='An Overlay')
o.icon = '<href>http://example.com/'
self.assertEqual(o.icon, '<href>http://example.com/</href>')
def test_icon_with_close_tag(self):
o = kml._Overlay(name='An Overlay')
o.icon = 'http://example.com/</href>'
self.assertEqual(o.icon, '<href>http://example.com/</href>')
def test_icon_with_tag(self):
o = kml._Overlay(name='An Overlay')
o.icon = '<href>http://example.com/</href>'
self.assertEqual(o.icon, '<href>http://example.com/</href>')
def test_icon_to_none(self):
o = kml._Overlay(name='An Overlay')
o.icon = '<href>http://example.com/</href>'
self.assertEqual(o.icon, '<href>http://example.com/</href>')
o.icon = None
self.assertEqual(o.icon, None)
def test_icon_raise_exception(self):
o = kml._Overlay(name='An Overlay')
with self.assertRaises(ValueError):
o.icon = 12345
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