예제 #1
0
 def invalidate_value(
         cls,
         value: Any,
         exc: Type[Exception] = EncodingTypeError,
         msg: Optional[str] = None,
 ) -> None:
     """
     Throws a standard exception for when a value is not encodable by an
     encoder.
     """
     raise exc(
         "Value `{rep}` of type {typ} cannot be encoded by {cls}{msg}".format(
             rep=abbr(value),
             typ=type(value),
             cls=cls.__name__,
             msg="" if msg is None else (": " + msg),
         )
     )
예제 #2
0
 def invalidate_value(
     cls,
     value: Any,
     exc: Type[Exception]=EncodingTypeError,
     msg: Optional[str]=None,
 ) -> None:
     """
     Throws a standard exception for when a value is not encodable by an
     encoder.
     """
     raise exc(
         "Value `{rep}` of type {typ} cannot be encoded by {cls}{msg}".format(
             rep=abbr(value),
             typ=type(value),
             cls=cls.__name__,
             msg="" if msg is None else (": " + msg),
         )
     )
예제 #3
0
def test_abbr_throws_value_errors():
    with pytest.raises(ValueError):
        abbr('asdf', limit=2)
예제 #4
0
def test_abbr(value, expected, limit):
    if limit is not None:
        actual = abbr(value, limit)
    else:
        actual = abbr(value)
    assert actual == expected
예제 #5
0
def test_abbr_throws_value_errors():
    with pytest.raises(ValueError):
        abbr('asdf', limit=2)
예제 #6
0
def test_abbr(value, expected, limit):
    if limit is not None:
        actual = abbr(value, limit)
    else:
        actual = abbr(value)
    assert actual == expected