示例#1
0
def test_missing_yaml_library() -> None:
    msg = "Missing yaml: pip install PyYAML"

    with patch("faust.serializers.codecs._yaml", None):
        with pytest.raises(ImproperlyConfigured):
            loads("yaml", dumps("yaml", DATA))
            pytest.fail(msg)

        with pytest.raises(ImproperlyConfigured):
            get_codec("yaml").loads(b"")
            pytest.fail(msg)
示例#2
0
def test_missing_yaml_library() -> None:
    msg = 'Missing yaml: pip install PyYAML'

    with patch('faust.serializers.codecs._yaml', None):
        with pytest.raises(ImproperlyConfigured):
            loads('yaml', dumps('yaml', DATA))
            pytest.fail(msg)

        with pytest.raises(ImproperlyConfigured):
            get_codec('yaml').loads(b'')
            pytest.fail(msg)
示例#3
0
def test_register():
    try:
        class MyCodec(Codec):
            ...
        register('mine', MyCodec)
        assert get_codec('mine') is MyCodec
    finally:
        codecs.pop('mine')
示例#4
0
def test_register():
    try:

        class MyCodec(Codec):
            ...

        register("mine", MyCodec)
        assert get_codec("mine") is MyCodec
    finally:
        codecs.pop("mine")
示例#5
0
def test_raw():
    bits = get_codec('raw').dumps('foo')
    assert isinstance(bits, bytes)
    assert get_codec('raw').loads(bits) == b'foo'
示例#6
0
def test_get_codec():
    assert get_codec('json|binary')
    assert get_codec(Codec) is Codec
示例#7
0
def test_raw():
    bits = get_codec("raw").dumps("foo")
    assert isinstance(bits, bytes)
    assert get_codec("raw").loads(bits) == b"foo"
示例#8
0
def test_get_codec():
    assert get_codec("json|binary")
    assert get_codec(Codec) is Codec
示例#9
0
from faust.serializers import codecs
from faust_s3_backed_serializer import S3BackedSerializer

import faust

broker = "kafka://localhost:9094"
input_topic = "texts"

app = faust.App("faust-s3-backed-demo", broker=broker)

value_serializer = "s3_backed_str_serializer"
str_serializer = codecs.get_codec("raw")
s3_serializer = S3BackedSerializer()
codecs.register(value_serializer, str_serializer | s3_serializer)

schema = faust.Schema(key_type=str,
                      key_serializer="raw",
                      value_type=str,
                      value_serializer=value_serializer)
texts_topic = app.topic(input_topic, schema=schema)


@app.agent(texts_topic)
async def print_length(texts):
    async for key, text in texts.items():
        print("{} has {} characters".format(key, len(text)))


if __name__ == '__main__':
    app.main()