def get_boolean_from_element(element: XmlElement, name: str) -> Optional[bool]: text = get_text_from_element(element, name) if text is None: return None return parse_bool(text.strip())
def test_str(self): self.assertTrue(parse_bool('1')) self.assertFalse(parse_bool('0')) self.assertFalse(parse_bool('')) self.assertFalse(parse_bool('foo'))
def test_int(self): self.assertTrue(parse_bool(1)) self.assertFalse(parse_bool(0)) self.assertFalse(parse_bool(12)) self.assertFalse(parse_bool(-1))
def test_none(self): self.assertIsNone(parse_bool(None))