Skip to content

Commit

Permalink
Convert test/ tests to Py.test
Browse files Browse the repository at this point in the history
Signed-off-by: Aarni Koskela <akx@iki.fi>
  • Loading branch information
akx committed Dec 23, 2023
1 parent c88511a commit e889845
Show file tree
Hide file tree
Showing 107 changed files with 445 additions and 993 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
test/ssl/demoCA
test/ssl/rootCA
test/ssl/signingCA
tests/ssl/demoCA
tests/ssl/rootCA
tests/ssl/signingCA
*.csr

# Translations
Expand Down
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file ensures py.test keeps this directory in sys.path,
# so you can run `py.test tests/lib`.
9 changes: 0 additions & 9 deletions test/Makefile

This file was deleted.

35 changes: 0 additions & 35 deletions test/lib/01-unpwd-set.py

This file was deleted.

37 changes: 0 additions & 37 deletions test/lib/01-unpwd-unicode-set.py

This file was deleted.

37 changes: 0 additions & 37 deletions test/lib/01-will-unpwd-set.py

This file was deleted.

15 changes: 0 additions & 15 deletions test/lib/08-ssl-bad-cacert.py

This file was deleted.

31 changes: 0 additions & 31 deletions test/lib/08-ssl-fake-cacert.py

This file was deleted.

37 changes: 0 additions & 37 deletions test/lib/Makefile

This file was deleted.

54 changes: 0 additions & 54 deletions test/lib/context.py

This file was deleted.

1 change: 0 additions & 1 deletion test/ssl/demoCA/serial

This file was deleted.

Empty file added tests/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions tests/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pathlib

tests_path = pathlib.Path(__file__).parent
ssl_path = tests_path / "ssl"
Empty file added tests/lib/__init__.py
Empty file.
7 changes: 2 additions & 5 deletions test/lib/python/01-asyncio.test → tests/lib/clients/01-asyncio.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env python3

import asyncio
import socket
import uuid

import context # Ensures paho is in PYTHONPATH

import paho.mqtt.client as mqtt

client_id = 'asyncio-test'


class AsyncioHelper:
def __init__(self, loop, client):
self.loop = loop
Expand Down Expand Up @@ -91,6 +87,7 @@ async def main(self):
await self.disconnected
rc = 0


rc = 1
loop = asyncio.get_event_loop()
loop.run_until_complete(AsyncMqttExample(loop).main())
Expand Down
16 changes: 7 additions & 9 deletions test/lib/python/01-decorators.test → tests/lib/clients/01-decorators.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
#!/usr/bin/env python3

import os
import socket
import subprocess
import sys
import time
from struct import *

import paho.mqtt.client as mqtt

run = -1
mqttc = mqtt.Client("decorators-test", run)
payload = b""


@mqttc.connect_callback()
def on_connect(mqttc, obj, flags, rc):
mqttc.subscribe("sub-test", 1)


@mqttc.subscribe_callback()
def on_subscribe(mqttc, obj, mid, granted_qos):
mqttc.unsubscribe("unsub-test")


@mqttc.unsubscribe_callback()
def on_unsubscribe(mqttc, obj, mid):
global payload
payload = "message"


@mqttc.message_callback()
def on_message(mqttc, obj, msg):
global payload
mqttc.publish("decorators", qos=1, payload=payload)


@mqttc.publish_callback()
def on_publish(mqttc, obj, mid):
mqttc.disconnect()


@mqttc.disconnect_callback()
def on_disconnect(mqttc, obj, rc):
obj = rc


mqttc.connect("localhost", 1888)
while run == -1:
mqttc.loop()
Expand Down
10 changes: 1 addition & 9 deletions test/lib/python/01-keepalive-pingreq.test → tests/lib/clients/01-keepalive-pingreq.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#!/usr/bin/env python3

import os
import socket
import subprocess
import sys
import time
from struct import *

import paho.mqtt.client as mqtt


def on_connect(mqttc, obj, flags, rc):
if rc != 0:
exit(rc)


run = -1
mqttc = mqtt.Client("01-keepalive-pingreq")
mqttc.on_connect = on_connect
Expand Down
2 changes: 0 additions & 2 deletions test/lib/python/01-no-clean-session.test → tests/lib/clients/01-no-clean-session.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

import paho.mqtt.client as mqtt

mqttc = mqtt.Client("01-no-clean-session", False)
Expand Down
Loading

0 comments on commit e889845

Please sign in to comment.