Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def test_compare_lt(a, b):
    assert Unit.parse(a) < b
Exemplo n.º 6
0
def test_compare_equal(a, b):
    assert Unit.parse(a) == b
Exemplo n.º 7
0
def test_compare_lt(a, b):
    assert Unit.parse(a) < b
Exemplo n.º 8
0
def test_compare_equal(a, b):
    assert Unit.parse(a) == b