def test_format_error(mocks: Mocks, context: yogi.Context): """Verifies that errors while formatting an object as a string get reported""" def fn(obj, str_, strsize, objfmt, nullstr): assert objfmt == b'foo' assert nullstr == b'bar' assert not strsize return yogi.ErrorCode.UNKNOWN mocks.MOCK_FormatObject(fn) with pytest.raises(yogi.FailureException): context.format('foo', 'bar')
def test_format(mocks: Mocks, context: yogi.Context, hello_bytes: bytes): """Verifies that an object can be formatted as a string""" def fn(obj, str_, strsize, objfmt, nullstr): assert obj == 1234 assert objfmt is None assert nullstr is None assert not strsize str_.contents.value = hello_bytes return yogi.ErrorCode.OK mocks.MOCK_FormatObject(fn) assert context.format() == 'hello'