support/testing: add test for python-avro
authorTitouan Christophe <titouan.christophe@railnova.eu>
Sun, 29 Dec 2019 20:29:12 +0000 (21:29 +0100)
committerYann E. MORIN <yann.morin.1998@free.fr>
Sun, 29 Dec 2019 20:38:33 +0000 (21:38 +0100)
This adds a test case for python-avro, with a script that
performs a simple deserialization.

Signed-off-by: Titouan Christophe <titouan.christophe@railnova.eu>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
support/testing/tests/package/sample_python_avro.py [new file with mode: 0644]
support/testing/tests/package/test_python_avro.py [new file with mode: 0644]

diff --git a/support/testing/tests/package/sample_python_avro.py b/support/testing/tests/package/sample_python_avro.py
new file mode 100644 (file)
index 0000000..79d2dcd
--- /dev/null
@@ -0,0 +1,23 @@
+from io import BytesIO
+from avro.schema import Parse
+from avro.io import DatumReader, BinaryDecoder
+
+schema = Parse("""{
+"namespace": "org.buildroot.package.python_avro",
+"type": "record",
+"name": "Developer",
+"fields": [
+    {"name": "email", "type": "string"},
+    {"name": "maintainer_of", "type": "string"}
+]
+}""")
+
+example = b'<titouan.christophe@railnova.eu\x16python_avro'
+
+reader = DatumReader(schema)
+deserialized = reader.read(BinaryDecoder(BytesIO(example)))
+
+assert deserialized == {
+    'email': 'titouan.christophe@railnova.eu',
+    'maintainer_of': 'python_avro',
+}
diff --git a/support/testing/tests/package/test_python_avro.py b/support/testing/tests/package/test_python_avro.py
new file mode 100644 (file)
index 0000000..6eee276
--- /dev/null
@@ -0,0 +1,11 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonAvro(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_AVRO=y
+        """
+    sample_scripts = ["tests/package/sample_python_avro.py"]