示例#1
0
def test_sNaN():
    with pytest.raises(ValueError):
        str_to_decimal('sNaN')
示例#2
0
 def _maybe_coerce(value: Union[str, Decimal] = None) -> Optional[Decimal]:
     if value is not None:
         if not isinstance(value, Decimal):
             return str_to_decimal(value)
         return value
     return None
示例#3
0
def test_Inf():
    with pytest.raises(ValueError):
        str_to_decimal('Inf')
示例#4
0
def test_negative_Inf():
    with pytest.raises(ValueError):
        str_to_decimal('-Inf')
示例#5
0
def test_str():
    d1 = Decimal('3.3333433434343434343434343434343')
    assert str_to_decimal(str(d1)) == d1
示例#6
0
def test_maxlen():
    s = '3.' + '34' * 1000
    with pytest.raises(ValueError):
        str_to_decimal(s)
示例#7
0
def test_str_to_decimal_None():
    assert str_to_decimal(None) is None
示例#8
0
def test_str_to_decimal_decimals(x):
    assume(x.is_finite())
    assert str_to_decimal(str(x)) == x
示例#9
0
def test_NaN():
    with pytest.raises(ValueError):
        str_to_decimal("NaN")
示例#10
0
def test_maxlen():
    s = "3." + "34" * 1000
    with pytest.raises(ValueError):
        str_to_decimal(s)
示例#11
0
 def _parse_decimal(typ: Type, data: Any) -> Optional[Decimal]:
     if data is None:
         return None
     if isinstance(data, Decimal):
         return data
     return str_to_decimal(cast(str, data))