From d86cd5b72ebcc14c871d42fc93c3b1d9760629f0 Mon Sep 17 00:00:00 2001 From: sessionm21 Date: Tue, 12 May 2020 22:01:21 +0100 Subject: [PATCH] seperate the tests --- main.py | 8 -------- tests.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 tests.py diff --git a/main.py b/main.py index c99250e..342b1a7 100644 --- a/main.py +++ b/main.py @@ -41,14 +41,6 @@ def on_message(client, userdata, msg): res.ParseFromString(bcode) store_coord(payload['dev_id'], res.loc.x, res.loc.y) -# Test protobuf here -# code = bytearray('CgoNAAAAABUAAAAA', "utf-8") -# print(code) -# bcode = base64.b64decode(code) -# res = message_pb2.CollarResponse() -# res.ParseFromString(bcode) -# print("Coord {x: " + str(res.loc.x) + ", y: " + str(res.loc.y) + "}") - client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..0c89831 --- /dev/null +++ b/tests.py @@ -0,0 +1,16 @@ +import paho.mqtt.client as mqtt +import json +import base64 +import message_pb2 +import sqlite3 + +# Test protobuf here +code = bytearray('CgoNAAAAABUAAAAA', "utf-8") +print(code) +bcode = base64.b64decode(code) +res = message_pb2.CollarResponse() +res.ParseFromString(bcode) + +assert res.loc.x == 0 +assert res.loc.y == 0 +print("Coord {x: " + str(res.loc.x) + ", y: " + str(res.loc.y) + "}")