xref: /OK3568_Linux_fs/buildroot/support/testing/tests/package/sample_python_avro.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1from io import BytesIO
2from avro.schema import Parse
3from avro.io import DatumReader, BinaryDecoder
4
5schema = Parse("""{
6"namespace": "org.buildroot.package.python_avro",
7"type": "record",
8"name": "Developer",
9"fields": [
10    {"name": "email", "type": "string"},
11    {"name": "maintainer_of", "type": "string"}
12]
13}""")
14
15example = b'<titouan.christophe@railnova.eu\x16python_avro'
16
17reader = DatumReader(schema)
18deserialized = reader.read(BinaryDecoder(BytesIO(example)))
19
20assert deserialized == {
21    'email': 'titouan.christophe@railnova.eu',
22    'maintainer_of': 'python_avro',
23}
24