Skip to content

Commit c679de4

Browse files
vogoltsovrandomsync
authored andcommitted
Added compatibility with Python3 and Robot Framework 3 (#13)
* Added compatibility with Python3 and Robot Framework 3. Signed-off-by: Vitaly Ogoltsov <[email protected]> * Version updated to 0.7.0. Signed-off-by: Vitaly Ogoltsov <[email protected]>
1 parent 14f2003 commit c679de4

10 files changed

+24
-17
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
language: python
22
services:
33
- docker
4+
dist:
5+
- 'xenial'
46
python:
57
- '2.7'
8+
- '3.7'
69
before_install:
710
- docker pull eclipse-mosquitto
811
- docker run -d -p 1883:1883 -p 9001:9001 -v $(pwd)/mosquitto:/mosquitto/config eclipse-mosquitto
912
install:
1013
- pip install -r requirements.txt
1114
script:
12-
- pybot -P src tests
15+
- robot -P src tests
1316
deploy:
1417
- provider: pypi
1518
user: randomsync

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
paho-mqtt==1.1
2-
robotframework==2.8.7
1+
paho-mqtt~=1.1
2+
robotframework~=3.0

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
# Get version
9-
execfile(join(here, 'src', 'MQTTLibrary', 'version.py'))
9+
exec(compile(open(join(here, 'src', 'MQTTLibrary', 'version.py'), "rb").read(), join(here, 'src', 'MQTTLibrary', 'version.py'), 'exec'))
1010

1111
# Get the long description
1212
with open(join(here, 'README.rst')) as f:
@@ -31,4 +31,4 @@
3131
package_dir = {'': 'src'},
3232
packages = ['MQTTLibrary'],
3333
install_requires = ['robotframework', 'paho-mqtt'],
34-
)
34+
)

src/MQTTLibrary/MQTTKeywords.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ def subscribe_and_validate(self, topic, qos, payload, timeout=1):
246246
self._verified = False
247247

248248
logger.info('Subscribing to topic: %s' % topic)
249-
self._mqttc.subscribe(str(topic), int(qos))
250249
self._payload = str(payload)
251250
self._mqttc.on_message = self._on_message
251+
self._mqttc.subscribe(str(topic), int(qos))
252252

253253
timer_start = time.time()
254254
while time.time() < timer_start + seconds:
@@ -406,16 +406,18 @@ def publish_multiple(self, msgs, hostname="localhost", port=1883,
406406
will, auth, tls, protocol)
407407

408408
def _on_message(self, client, userdata, message):
409+
payload = message.payload.decode('utf-8')
409410
logger.debug('Received message: %s on topic: %s with QoS: %s'
410-
% (str(message.payload), message.topic, str(message.qos)))
411-
self._verified = re.match(self._payload, str(message.payload))
411+
% (payload, message.topic, str(message.qos)))
412+
self._verified = re.match(self._payload, payload)
412413

413414
def _on_message_list(self, client, userdata, message):
415+
payload = message.payload.decode('utf-8')
414416
logger.debug('Received message: %s on topic: %s with QoS: %s'
415-
% (str(message.payload), message.topic, str(message.qos)))
417+
% (payload, message.topic, str(message.qos)))
416418
if message.topic not in self._messages:
417419
self._messages[message.topic] = []
418-
self._messages[message.topic].append(message.payload)
420+
self._messages[message.topic].append(payload)
419421

420422
def _on_connect(self, client, userdata, flags, rc):
421423
self._connected = True if rc == 0 else False

src/MQTTLibrary/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from MQTTKeywords import MQTTKeywords
2-
from version import VERSION
1+
from MQTTLibrary.MQTTKeywords import MQTTKeywords
2+
from MQTTLibrary.version import VERSION
33

44
__version__ = VERSION
55

@@ -17,4 +17,4 @@ class MQTTLibrary(MQTTKeywords):
1717
"""
1818

1919
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
20-
ROBOT_LIBRARY_VERSION = __version__
20+
ROBOT_LIBRARY_VERSION = __version__

src/MQTTLibrary/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '0.6.1'
1+
VERSION = '0.7.0'

tests/connect.txt renamed to tests/connect.robot

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*** Settings ***
2+
| Library | String
23
| Library | MQTTLibrary
34
| Test Timeout | 30 seconds
45

@@ -12,7 +13,8 @@
1213
| *Test Cases*
1314
| Connect to a broker with default port and client id
1415
| | ${mqttc} | Connect | ${broker.uri}
15-
| | Should Match Regexp | ${mqttc._client_id} | ^paho/[0-9A-f]{18}
16+
| | ${client_id} = | Decode Bytes To String | ${mqttc._client_id} | UTF-8
17+
| | Should Be Empty | ${client_id} |
1618
| | [Teardown] | Disconnect
1719

1820
| Connect to a broker with default port and specified client id
File renamed without changes.
File renamed without changes.

tests/pubsub.txt renamed to tests/pubsub.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
| *Settings* | *Value*
2-
| Resource | keywords.txt
2+
| Resource | keywords.robot
33
| Test Timeout | 30 seconds
44

55
| *Test Cases*
@@ -213,4 +213,4 @@
213213
| | Length Should Be | ${messages2} | 2
214214
| | Should Be Equal As Strings | @{messages2}[0] | test message1
215215
| | Should Be Equal As Strings | @{messages2}[1] | test message3
216-
| | [Teardown] | Unsubscribe Multiple and Disconnect | ${topic1} |${topic2}
216+
| | [Teardown] | Unsubscribe Multiple and Disconnect | ${topic1} | ${topic2}

0 commit comments

Comments
 (0)