Skip to content
Snippets Groups Projects
Commit 65320d73 authored by fxk8y's avatar fxk8y :spider:
Browse files

Adding topic matcher testing stuff

parent 441ff513
No related branches found
No related tags found
No related merge requests found
......@@ -493,13 +493,16 @@ class SpiderMQTT:
self.__shutdownFunc()
import time
s = SpiderMQTT('192.168.0.42')
time.sleep(0.25)
# import time
# s = SpiderMQTT('192.168.0.42')
# time.sleep(0.25)
# s.request('device/HPDL-1414/fxbuffer/size/get', 'device/HPDL-1414/fxbuffer/size', '', print)
s.request('device/HPDL-1414/fxbuffer/size/get', 'device/HPDL-1414/fxbuffer/size', '', print)
# s.subscribe('spider', print)
# s.publish('spider', 'SpiderMQTT - The eight-legged MQTT request library')
......
#!/usr/bin/env nix-shell
#!nix-shell -i python -p "python3.withPackages(ps : with ps; [ pyyaml paho-mqtt ])"
from cProfile import run
from SpiderMQTT import Topic
# Test data according to https://github.com/eclipse/mosquitto/blob/master/test/unit/util_topic_test.c
topicsMatching = [
('foo/#', 'foo/'),
('foo/#', 'foo'),
('foo//bar', 'foo//bar'),
('foo//+', 'foo//bar'),
('foo/+/+/baz', 'foo///baz'),
('foo/bar/+', 'foo/bar/'),
('foo/bar', 'foo/bar'),
('foo/+', 'foo/bar'),
('foo/+/baz', 'foo/bar/baz'),
('A/B/+/#', 'A/B/B/C'),
('foo/+/#', 'foo/bar/baz'),
('foo/+/#', 'foo/bar'),
('#', 'foo/bar/baz'),
('#', 'foo/bar/baz'),
('#', '/foo/bar'),
('/#', '/foo/bar')
]
topicsNotMatching = [
('test/6/#', 'test/3'),
('foo/bar', 'foo'),
('foo/+', 'foo/bar/baz'),
('foo/+/baz', 'foo/bar/bar'),
('foo/+/#', 'fo2/bar/baz'),
('/#', 'foo/bar'),
('#', '$SYS/bar'),
('$BOB/bar', '$SYS/bar')
]
def runTest(t0: str, t1: str, expectation: bool):
result = Topic.compare(t0, t1) == expectation
expStr = '==' if expectation else '!='
resultSym = '' if result else ''
resultStr = 'PASSED' if result else 'FAILED'
print(f'[ {resultSym} ] Test: [ {t0} ] {expStr} [ {t1} ] {resultStr}')
def runTestGroup(group: list, expectation: bool):
for pair in group:
runTest(*pair, expectation)
if __name__ == '__main__':
headLine = ' Testing the TopicMatcher of SpiderMQTT '
print(f'\n{headLine}\n{"="*len(headLine)}\n')
runTestGroup(topicsMatching, True)
print('\n')
runTestGroup(topicsNotMatching, False)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment