Skip to content

Commit

Permalink
Added compatibility with Python3 and Robot Framework 3 (#13)
Browse files Browse the repository at this point in the history
* Added compatibility with Python3 and Robot Framework 3.

Signed-off-by: Vitaly Ogoltsov <vitaly.ogoltsov@me.com>

* Version updated to 0.7.0.

Signed-off-by: Vitaly Ogoltsov <vitaly.ogoltsov@me.com>
  • Loading branch information
vogoltsov authored and randomsync committed Jul 22, 2019
1 parent 14f2003 commit c679de4
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
language: python
services:
- docker
dist:
- 'xenial'
python:
- '2.7'
- '3.7'
before_install:
- docker pull eclipse-mosquitto
- docker run -d -p 1883:1883 -p 9001:9001 -v $(pwd)/mosquitto:/mosquitto/config eclipse-mosquitto
install:
- pip install -r requirements.txt
script:
- pybot -P src tests
- robot -P src tests
deploy:
- provider: pypi
user: randomsync
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
paho-mqtt==1.1
robotframework==2.8.7
paho-mqtt~=1.1
robotframework~=3.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


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

# Get the long description
with open(join(here, 'README.rst')) as f:
Expand All @@ -31,4 +31,4 @@
package_dir = {'': 'src'},
packages = ['MQTTLibrary'],
install_requires = ['robotframework', 'paho-mqtt'],
)
)
12 changes: 7 additions & 5 deletions src/MQTTLibrary/MQTTKeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ def subscribe_and_validate(self, topic, qos, payload, timeout=1):
self._verified = False

logger.info('Subscribing to topic: %s' % topic)
self._mqttc.subscribe(str(topic), int(qos))
self._payload = str(payload)
self._mqttc.on_message = self._on_message
self._mqttc.subscribe(str(topic), int(qos))

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

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

def _on_message_list(self, client, userdata, message):
payload = message.payload.decode('utf-8')
logger.debug('Received message: %s on topic: %s with QoS: %s'
% (str(message.payload), message.topic, str(message.qos)))
% (payload, message.topic, str(message.qos)))
if message.topic not in self._messages:
self._messages[message.topic] = []
self._messages[message.topic].append(message.payload)
self._messages[message.topic].append(payload)

def _on_connect(self, client, userdata, flags, rc):
self._connected = True if rc == 0 else False
Expand Down
6 changes: 3 additions & 3 deletions src/MQTTLibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from MQTTKeywords import MQTTKeywords
from version import VERSION
from MQTTLibrary.MQTTKeywords import MQTTKeywords
from MQTTLibrary.version import VERSION

__version__ = VERSION

Expand All @@ -17,4 +17,4 @@ class MQTTLibrary(MQTTKeywords):
"""

ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = __version__
ROBOT_LIBRARY_VERSION = __version__
2 changes: 1 addition & 1 deletion src/MQTTLibrary/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.6.1'
VERSION = '0.7.0'
4 changes: 3 additions & 1 deletion tests/connect.txt → tests/connect.robot
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*** Settings ***
| Library | String
| Library | MQTTLibrary
| Test Timeout | 30 seconds

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

| Connect to a broker with default port and specified client id
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/pubsub.txt → tests/pubsub.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| *Settings* | *Value*
| Resource | keywords.txt
| Resource | keywords.robot
| Test Timeout | 30 seconds

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

0 comments on commit c679de4

Please sign in to comment.