def value(self): # Try parsing a number try: return int(self.text_value) except (ValueError, TypeError): try: return float(self.text_value) except (ValueError, TypeError): try: return Unit.parse(self.text_value) except ValueError: return self.text_value
def value_of(text_value, remove_comma=True): """Converts string value to Int, Float or String Args: remove_comma: When we set this value as True, removes all comma from the string. Default True """ if remove_comma: text_value = text_value.replace(',', '') # Try parsing a number try: return int(text_value) except (ValueError, TypeError): try: return float(text_value) except (ValueError, TypeError): try: return Unit.parse(text_value) except ValueError: return text_value
def test_compare_lt(a, b): assert Unit.parse(a) < b
def test_compare_equal(a, b): assert Unit.parse(a) == b