diff mbox series

[2/2] support/testing/tests/package/test_python_paho_mqtt: new runtime test

Message ID 20220823194732.701895-2-marcus.hoffmann@othermo.de
State Superseded
Headers show
Series [1/2] package/python-paho-mqtt: bump to 1.6.1 to fix running on python 3.10 | expand

Commit Message

Marcus Hoffmann Aug. 23, 2022, 7:47 p.m. UTC
Signed-off-by: Marcus Hoffmann <marcus.hoffmann@othermo.de>
---
 .../tests/package/sample_python_paho_mqtt.py  | 12 ++++++++
 .../tests/package/test_python_paho_mqtt.py    | 29 +++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 support/testing/tests/package/sample_python_paho_mqtt.py
 create mode 100644 support/testing/tests/package/test_python_paho_mqtt.py

Comments

Arnout Vandecappelle Aug. 24, 2022, 8:45 p.m. UTC | #1
On 23/08/2022 21:47, Marcus Hoffmann wrote:
> Signed-off-by: Marcus Hoffmann <marcus.hoffmann@othermo.de>
Tested-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>

Tested that without the first patch, the test indeed fails with

# python sample_python_paho_mqtt.py
Traceback (most recent call last):
   File "/root/sample_python_paho_mqtt.py", line 3, in <module>
     publish.single(
   File "usr/lib/python3.10/site-packages/paho/mqtt/publish.py", line 222, in single
   File "usr/lib/python3.10/site-packages/paho/mqtt/publish.py", line 126, in 
multiple
AttributeError: module 'collections' has no attribute 'Iterable'


  Regards,
  Arnout

> ---
>   .../tests/package/sample_python_paho_mqtt.py  | 12 ++++++++
>   .../tests/package/test_python_paho_mqtt.py    | 29 +++++++++++++++++++
>   2 files changed, 41 insertions(+)
>   create mode 100644 support/testing/tests/package/sample_python_paho_mqtt.py
>   create mode 100644 support/testing/tests/package/test_python_paho_mqtt.py
> 
> diff --git a/support/testing/tests/package/sample_python_paho_mqtt.py b/support/testing/tests/package/sample_python_paho_mqtt.py
> new file mode 100644
> index 00000000000..769ad6250fa
> --- /dev/null
> +++ b/support/testing/tests/package/sample_python_paho_mqtt.py
> @@ -0,0 +1,12 @@
> +from paho.mqtt import publish, subscribe
> +
> +publish.single(
> +        'buildroot/test',
> +        payload="Hello, World!",
> +        qos=2,
> +        retain=True,
> +        hostname="localhost",
> +        port=1883)
> +
> +message = subscribe.simple('buildroot/test')
> +print(message.payload.decode())
> diff --git a/support/testing/tests/package/test_python_paho_mqtt.py b/support/testing/tests/package/test_python_paho_mqtt.py
> new file mode 100644
> index 00000000000..b1e2b8fb422
> --- /dev/null
> +++ b/support/testing/tests/package/test_python_paho_mqtt.py
> @@ -0,0 +1,29 @@
> +from tests.package.test_python import TestPythonPackageBase
> +import os
> +import time
> +
> +
> +class TestPythonPahoMQTT(TestPythonPackageBase):
> +    __test__ = True
> +    config = TestPythonPackageBase.config + \
> +        """
> +        BR2_PACKAGE_MOSQUITTO=y
> +        BR2_PACKAGE_MOSQUITTO_BROKER=y
> +        BR2_PACKAGE_PYTHON3=y
> +        BR2_PACKAGE_PYTHON_PAHO_MQTT=y
> +        """
> +    sample_scripts = ["tests/package/sample_python_paho_mqtt.py"]
> +
> +    def test_run(self):
> +        self.login()
> +        self.check_sample_scripts_exist()
> +        cmd = "mosquitto > /dev/null 2>&1 &"
> +        _, exit_code = self.emulator.run(cmd, timeout=self.timeout)
> +
> +        # Give some time for mosquitto broker to start up
> +        time.sleep(1)
> +
> +        cmd = "%s %s" % (self.interpreter, os.path.basename(self.sample_scripts[0]))
> +        output, exit_code = self.emulator.run(cmd, timeout=self.timeout)
> +        self.assertEqual(exit_code, 0)
> +        self.assertEqual(output[0], "Hello, World!")
diff mbox series

Patch

diff --git a/support/testing/tests/package/sample_python_paho_mqtt.py b/support/testing/tests/package/sample_python_paho_mqtt.py
new file mode 100644
index 00000000000..769ad6250fa
--- /dev/null
+++ b/support/testing/tests/package/sample_python_paho_mqtt.py
@@ -0,0 +1,12 @@ 
+from paho.mqtt import publish, subscribe
+
+publish.single(
+        'buildroot/test',
+        payload="Hello, World!",
+        qos=2,
+        retain=True,
+        hostname="localhost",
+        port=1883)
+
+message = subscribe.simple('buildroot/test')
+print(message.payload.decode())
diff --git a/support/testing/tests/package/test_python_paho_mqtt.py b/support/testing/tests/package/test_python_paho_mqtt.py
new file mode 100644
index 00000000000..b1e2b8fb422
--- /dev/null
+++ b/support/testing/tests/package/test_python_paho_mqtt.py
@@ -0,0 +1,29 @@ 
+from tests.package.test_python import TestPythonPackageBase
+import os
+import time
+
+
+class TestPythonPahoMQTT(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_MOSQUITTO=y
+        BR2_PACKAGE_MOSQUITTO_BROKER=y
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_PAHO_MQTT=y
+        """
+    sample_scripts = ["tests/package/sample_python_paho_mqtt.py"]
+
+    def test_run(self):
+        self.login()
+        self.check_sample_scripts_exist()
+        cmd = "mosquitto > /dev/null 2>&1 &"
+        _, exit_code = self.emulator.run(cmd, timeout=self.timeout)
+
+        # Give some time for mosquitto broker to start up
+        time.sleep(1)
+
+        cmd = "%s %s" % (self.interpreter, os.path.basename(self.sample_scripts[0]))
+        output, exit_code = self.emulator.run(cmd, timeout=self.timeout)
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(output[0], "Hello, World!")