diff --git a/fastkml/styles.py b/fastkml/styles.py index 48240c65..e4521b4c 100644 --- a/fastkml/styles.py +++ b/fastkml/styles.py @@ -352,9 +352,7 @@ def strtobool(val: str) -> int: val = val.lower() if val == "false": return 0 - if val == "true": - return 1 - return int(float(val)) + return 1 if val == "true" else int(float(val)) super().from_element(element) fill = element.find(f"{self.ns}fill") @@ -628,7 +626,7 @@ def from_element(self, element: Element) -> None: key = pair.find(f"{self.ns}key") style = pair.find(f"{self.ns}Style") style_url = pair.find(f"{self.ns}styleUrl") - if key is None: + if key is None or key.text not in ["highlight", "normal"]: raise ValueError elif key.text == "highlight": if style is not None: @@ -640,7 +638,7 @@ def from_element(self, element: Element) -> None: else: raise ValueError self.highlight = highlight - elif key.text == "normal": + else: if style is not None: normal = Style(self.ns) normal.from_element(style) @@ -650,8 +648,6 @@ def from_element(self, element: Element) -> None: else: raise ValueError self.normal = normal - else: - raise ValueError def etree_element( self, diff --git a/tests/base_test.py b/tests/base_test.py index 5158ca0d..4b6b242e 100644 --- a/tests/base_test.py +++ b/tests/base_test.py @@ -72,7 +72,7 @@ class Test(base._BaseObject): def test_base_from_element_raises(self) -> None: be = base._BaseObject() - element = cast(types.Element, config.etree.Element(config.KMLNS + "Base")) # type: ignore[attr-defined] + element = cast(types.Element, config.etree.Element(f"{config.KMLNS}Base")) with pytest.raises(TypeError): be.from_element(element=element)