summaryrefslogtreecommitdiffstats
path: root/lang/python/python-paho-mqtt/test.sh
blob: 2815fbc517b0a080f64c03b28b68db02bd4e7b8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
[ "$1" = python3-paho-mqtt ] || exit 0

python3 - << 'EOF'
import paho.mqtt.client as mqtt

# Verify version
assert hasattr(mqtt, '__version__') or hasattr(mqtt.Client, '__module__')

# Test basic client instantiation
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
assert client is not None

# Test that the client has expected methods
assert callable(getattr(client, 'connect', None))
assert callable(getattr(client, 'publish', None))
assert callable(getattr(client, 'subscribe', None))
assert callable(getattr(client, 'disconnect', None))

# Test MQTTMessage
msg = mqtt.MQTTMessage(topic=b'test/topic')
msg.payload = b'hello'
assert msg.topic == 'test/topic'
assert msg.payload == b'hello'

print("paho-mqtt OK")
EOF