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), ) )
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), ) )
def test_abbr_throws_value_errors(): with pytest.raises(ValueError): abbr('asdf', limit=2)
def test_abbr(value, expected, limit): if limit is not None: actual = abbr(value, limit) else: actual = abbr(value) assert actual == expected