Made Python files compliant with PEP8, except for E501

This commit is contained in:
Paulo Martinez 2017-04-12 09:39:36 +02:00
parent 4c8ce14dad
commit 10925659ef
3 changed files with 233 additions and 240 deletions

View File

@ -1,14 +1,13 @@
import unittest import unittest
import settings import settings
import time import time
import mosquitto import mosquitto
import serial
def on_message(mosq, obj, msg): def on_message(mosq, obj, msg):
obj.message_queue.append(msg) obj.message_queue.append(msg)
class mqtt_basic(unittest.TestCase): class mqtt_basic(unittest.TestCase):
message_queue = [] message_queue = []
@ -38,6 +37,3 @@ class mqtt_basic(unittest.TestCase):
self.assertEqual(msg.payload, "hello world") self.assertEqual(msg.payload, "hello world")
self.assertEqual(msg.qos, 0, "message qos not 0") self.assertEqual(msg.qos, 0, "message qos not 0")
self.assertEqual(msg.retain, False, "message retain flag incorrect") self.assertEqual(msg.retain, False, "message retain flag incorrect")

View File

@ -1,14 +1,13 @@
import unittest import unittest
import settings import settings
import time import time
import mosquitto import mosquitto
import serial
def on_message(mosq, obj, msg): def on_message(mosq, obj, msg):
obj.message_queue.append(msg) obj.message_queue.append(msg)
class mqtt_publish_in_callback(unittest.TestCase): class mqtt_publish_in_callback(unittest.TestCase):
message_queue = [] message_queue = []
@ -39,7 +38,6 @@ class mqtt_publish_in_callback(unittest.TestCase):
self.assertEqual(msg.qos, 0, "message qos not 0") self.assertEqual(msg.qos, 0, "message qos not 0")
self.assertEqual(msg.retain, False, "message retain flag incorrect") self.assertEqual(msg.retain, False, "message retain flag incorrect")
def test_publish(self): def test_publish(self):
self.assertEqual(len(self.message_queue), 0, "message queue not empty") self.assertEqual(len(self.message_queue), 0, "message queue not empty")
payload = "abcdefghij" payload = "abcdefghij"
@ -59,6 +57,3 @@ class mqtt_publish_in_callback(unittest.TestCase):
self.assertEqual(msg.payload, payload) self.assertEqual(msg.payload, payload)
self.assertEqual(msg.qos, 0, "message qos not 0") self.assertEqual(msg.qos, 0, "message qos not 0")
self.assertEqual(msg.retain, False, "message retain flag incorrect") self.assertEqual(msg.retain, False, "message retain flag incorrect")

View File

@ -10,21 +10,22 @@ import re
from testcases import settings from testcases import settings
class Workspace(object): class Workspace(object):
def __init__(self): def __init__(self):
self.root_dir = os.getcwd() self.root_dir = os.getcwd()
self.build_dir = os.path.join(self.root_dir,"tmpbin"); self.build_dir = os.path.join(self.root_dir, "tmpbin")
self.log_dir = os.path.join(self.root_dir,"logs"); self.log_dir = os.path.join(self.root_dir, "logs")
self.tests_dir = os.path.join(self.root_dir,"testcases"); self.tests_dir = os.path.join(self.root_dir, "testcases")
self.examples_dir = os.path.join(self.root_dir, "../PubSubClient/examples") self.examples_dir = os.path.join(self.root_dir, "../PubSubClient/examples")
self.examples = [] self.examples = []
self.tests = [] self.tests = []
if not os.path.isdir("../PubSubClient"): if not os.path.isdir("../PubSubClient"):
raise Exception("Cannot find PubSubClient library") raise Exception("Cannot find PubSubClient library")
try: try:
import ino return __import__('ino')
except: except ImportError:
raise Exception("ino tool not installed") raise Exception("ino tool not installed")
def init(self): def init(self):
@ -57,6 +58,7 @@ class Workspace(object):
def clean(self): def clean(self):
shutil.rmtree(self.build_dir) shutil.rmtree(self.build_dir)
class Sketch(object): class Sketch(object):
def __init__(self, wksp, fn): def __init__(self, wksp, fn):
self.w = wksp self.w = wksp
@ -100,7 +102,7 @@ class Sketch(object):
sys.stdout.write("\n") sys.stdout.write("\n")
with open(self.build_err_log) as f: with open(self.build_err_log) as f:
for line in f: for line in f:
print " ",line, print(" " + line)
return False return False
def upload(self): def upload(self):
@ -118,10 +120,9 @@ class Sketch(object):
sys.stdout.write("\n") sys.stdout.write("\n")
with open(self.build_upload_log) as f: with open(self.build_upload_log) as f:
for line in f: for line in f:
print " ",line, print(" " + line)
return False return False
def test(self): def test(self):
# import the matching test case, if it exists # import the matching test case, if it exists
try: try:
@ -146,19 +147,20 @@ class Sketch(object):
sys.stdout.flush() sys.stdout.flush()
for t in tests: for t in tests:
t.run(result) t.run(result)
print "%d/%d"%(result.testsRun-len(result.failures)-len(result.errors),result.testsRun) print(str(result.testsRun - len(result.failures) - len(result.errors)) + "/" + str(result.testsRun))
if not result.wasSuccessful(): if not result.wasSuccessful():
if len(result.failures) > 0: if len(result.failures) > 0:
for f in result.failures: for f in result.failures:
print "-- %s"%(str(f[0]),) print("-- " + str(f[0]))
print f[1] print(f[1])
if len(result.errors) > 0: if len(result.errors) > 0:
print " Errors:" print(" Errors:")
for f in result.errors: for f in result.errors:
print "-- %s"%(str(f[0]),) print("-- " + str(f[0]))
print f[1] print(f[1])
c.tearDownClass() c.tearDownClass()
if __name__ == '__main__': if __name__ == '__main__':
run_tests = True run_tests = True
@ -166,13 +168,13 @@ if __name__ == '__main__':
w.init() w.init()
for e in w.examples: for e in w.examples:
print "--------------------------------------" print("--------------------------------------")
print "[%s]"%(e.basename,) print("[" + e.basename + "]")
if e.build() and run_tests: if e.build() and run_tests:
e.test() e.test()
for e in w.tests: for e in w.tests:
print "--------------------------------------" print("--------------------------------------")
print "[%s]"%(e.basename,) print("[" + e.basename + "]")
if e.build() and run_tests: if e.build() and run_tests:
e.test() e.test()