Commit 366313b8 authored by Ian Lee's avatar Ian Lee

Fix a bug when the fill or outline attributes of a PolyStyle are float strings, e.g. "0.0"

parent 8b88dc6b
...@@ -4,6 +4,8 @@ Changelog ...@@ -4,6 +4,8 @@ Changelog
0.10 (unreleased) 0.10 (unreleased)
----------------- -----------------
- Fix bug when the fill or outline attributes of a PolyStyle are float strings
0.9 (2014/10/17) 0.9 (2014/10/17)
----------------- -----------------
......
...@@ -353,10 +353,10 @@ class PolyStyle(_ColorStyle): ...@@ -353,10 +353,10 @@ class PolyStyle(_ColorStyle):
super(PolyStyle, self).from_element(element) super(PolyStyle, self).from_element(element)
fill = element.find('%sfill' % self.ns) fill = element.find('%sfill' % self.ns)
if fill is not None: if fill is not None:
self.fill = int(fill.text) self.fill = int(float(fill.text))
outline = element.find('%soutline' % self.ns) outline = element.find('%soutline' % self.ns)
if outline is not None: if outline is not None:
self.outline = int(outline.text) self.outline = int(float(outline.text))
class LabelStyle(_ColorStyle): class LabelStyle(_ColorStyle):
......
...@@ -934,6 +934,12 @@ class StyleTestCase(unittest.TestCase): ...@@ -934,6 +934,12 @@ class StyleTestCase(unittest.TestCase):
f2.from_string(f.to_string(prettyprint=True)) f2.from_string(f.to_string(prettyprint=True))
self.assertEqual(f.to_string(), f2.to_string()) self.assertEqual(f.to_string(), f2.to_string())
def test_polystyle_fill(self):
style = styles.PolyStyle()
def test_polystyle_outline(self):
style = styles.PolyStyle()
class StyleUsageTestCase(unittest.TestCase): class StyleUsageTestCase(unittest.TestCase):
def test_create_document_style(self): def test_create_document_style(self):
...@@ -1164,6 +1170,48 @@ class StyleFromStringTestCase(unittest.TestCase): ...@@ -1164,6 +1170,48 @@ class StyleFromStringTestCase(unittest.TestCase):
k2.from_string(k.to_string()) k2.from_string(k.to_string())
self.assertEqual(k.to_string(), k2.to_string()) self.assertEqual(k.to_string(), k2.to_string())
def test_polystyle_float_fill(self):
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>PolygonStyle.kml</name>
<open>1</open>
<Style id="examplePolyStyle">
<PolyStyle>
<fill>0.0</fill>
</PolyStyle>
</Style>
</Document>
</kml>"""
k = kml.KML()
k.from_string(doc)
style = list(list(list(k.features())[0].styles())[0].styles())[0]
self.assertTrue(isinstance(style, styles.PolyStyle))
self.assertEqual(style.fill, 0)
k2 = kml.KML()
k2.from_string(k.to_string())
self.assertEqual(k.to_string(), k2.to_string())
def test_polystyle_float_outline(self):
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>PolygonStyle.kml</name>
<open>1</open>
<Style id="examplePolyStyle">
<PolyStyle>
<outline>0.0</outline>
</PolyStyle>
</Style>
</Document>
</kml>"""
k = kml.KML()
k.from_string(doc)
style = list(list(list(k.features())[0].styles())[0].styles())[0]
self.assertTrue(isinstance(style, styles.PolyStyle))
self.assertEqual(style.outline, 0)
k2 = kml.KML()
k2.from_string(k.to_string())
self.assertEqual(k.to_string(), k2.to_string())
def test_styles(self): def test_styles(self):
doc = """<kml xmlns="http://www.opengis.net/kml/2.2"> doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document> <Document>
......
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