Skip to content

Commit

Permalink
almost 'pylint clean"
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroendoggen committed Jan 4, 2013
1 parent a8bdf3b commit 9a41ca0
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 166 deletions.
2 changes: 1 addition & 1 deletion arduino_testsuite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Initialize the package
""" arduino_testsuite: Initialize the package
This file is needed to import the module properly
The version number is used to generate the PyPI package
Expand Down
2 changes: 1 addition & 1 deletion arduino_testsuite/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Main file to run
""" arduino_testsuite: Main file to run
This file is needed to be able to run a Python program in a folder directly
by calling "Python foldername"
Expand Down
6 changes: 4 additions & 2 deletions arduino_testsuite/infoprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ def planned_tests(test_list):
programflow()


def setup_info(item):
def setup_info(index, current_test):
"""Print text at start of a test."""
print ("")
double_line()
print ("Starting test: " + item)
print ("Starting test ", end="")
print (index + 1, end=": ")
print (current_test)
single_line()
print ("Compiling & uploading sketch to Arduino...")

Expand Down
8 changes: 4 additions & 4 deletions arduino_testsuite/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def run():
"""Run the main program"""
suite = TestSuite()
timeout = 10
suite.printPlannedTests()
suite.runTests(timeout)
suite.printSummary()
return(suite.exitValue())
suite.print_planned_tests()
suite.run_tests(timeout)
suite.print_summary()
return(suite.exit_value())


if __name__ == "__main__":
Expand Down
56 changes: 24 additions & 32 deletions arduino_testsuite/settings.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
#!/usr/bin/env python
#
# Arduino TestSuite to automate unit tests on the Arduino platform
# Copyright (C) 2012 Jeroen Doggen <jeroendoggen@gmail.com>
# More info in "main.py"
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
""" arduino_testsuite: Settings class
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
get the cli arguments
setup the serial port
read the config file
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""

from __future__ import print_function, division # We require Python 2.6+

Expand All @@ -30,18 +17,23 @@
logging.basicConfig(filename='example.log',
level=logging.DEBUG,
format='%(asctime)s %(name)s %(message)s')
logger = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)


class Settings:
"""Configure the settings of the program"""
DEFAULT_PORT = "/dev/ttyUSB0"
DEFAULT_BAUDRATE = 9600
DEFAULT_CONFIGFILE = "planned-tests.conf"
serialPort = DEFAULT_PORT
serial_port = DEFAULT_PORT
baudrate = DEFAULT_BAUDRATE
configFile = DEFAULT_CONFIGFILE
config_file = DEFAULT_CONFIGFILE

def getCliArguments(self):
def __init__(self):
"""Initialize the settings: do nothing for now."""
pass

def get_cli_arguments(self):
"""Read all the cli arguments."""
"""This needs to be indented like this to print it correctly on cli"""
parser = argparse.ArgumentParser(
Expand All @@ -59,32 +51,32 @@ def getCliArguments(self):
help='Set the baudrate of the serial port')
args = parser.parse_args()
if (args.p is not None):
self.serialPort = args.p
self.serial_port = args.p
if (args.f is not None):
self.configFile = args.f
self.config_file = args.f
if (args.b is not None):
self.baudrate = args.b

def initSerialPort(self):
def init_serial_port(self):
"""Initialize the serial port."""
try:
ser = serial.Serial(self.serialPort, self.baudrate)
ser = serial.Serial(self.serial_port, self.baudrate)
ser.flush()
except IOError:
logger.warning("Unable to connect to serial port")
print("Unable to connect to serial port: ", end="")
print(self.serialPort)
print(self.serial_port)
sys.exit(1)
return(ser)

def readConfigfile(self):
def read_testlist_file(self):
"""Read the config file to get the testlist."""
testList = []
test_list = []
try:
with open(self.configFile, 'r') as f:
testList = f.read().splitlines()
with open(self.config_file, 'r') as configfile:
test_list = configfile.read().splitlines()
except IOError:
print ("Error: 'planned-tests.conf' not found!")
print ("Aborting test session.")
sys.exit(1)
return testList
return test_list
20 changes: 13 additions & 7 deletions arduino_testsuite/test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
""" arduino_testsuite: Unit tests
nothing useful in here at the moment
"""

import unittest
import random

from arduino_testsuite.testhelper import TestHelper

helper = TestHelper()
class ArduinoTestSuite(unittest.TestCase):
"""Test the Arduino
this part of the code could/should be called by 'nose' in the future
class testArduino(unittest.TestCase):
"""

def setUp(self):
self.seq = range(10)
def setup(self):
"""Do the test setup"""
pass

def test_runArduinoTests(self):
def test_run_arduino_tests(self):
"""Run the tests on the hardware"""
self.assertEqual(0, 0)


Expand Down
46 changes: 22 additions & 24 deletions arduino_testsuite/testhelper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
""" arduino_testsuite: Test helper functions
run a command with a given timeout
return the exit value for the program
"""

from __future__ import print_function, division # We require Python 2.6+

import time
Expand All @@ -7,28 +14,19 @@
import signal


class TestHelper:
def timeout_command(self, command, timeout):
#"""call shell-command and either return its output or kill it
#if it doesn't normally exit within timeout seconds and return None"""

cmd = command.split(" ")
start = datetime.datetime.now()
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

while process.poll() is None:
now = datetime.datetime.now()
time.sleep(1)
if (now - start).seconds > timeout:
print ("Process timeout")
os.kill(process.pid, signal.SIGKILL)
os.waitpid(-1, os.WNOHANG)
return None
return process.poll()
def timed_cmd(command, timeout):
"""Call a cmd and kill it after 'timeout' seconds"""
cmd = command.split(" ")
start = datetime.datetime.now()
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

def exitValue(self, failureCount):
if (failureCount == 0):
return 0
else:
return 42
while process.poll() is None:
now = datetime.datetime.now()
time.sleep(1)
if (now - start).seconds > timeout:
print ("Process timeout")
os.kill(process.pid, signal.SIGKILL)
os.waitpid(-1, os.WNOHANG)
return None
return process.poll()
17 changes: 4 additions & 13 deletions arduino_testsuite/tests/test.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import unittest
import random

from arduino_testsuite.testhelper import TestHelper

helper = TestHelper()

class testArduino(unittest.TestCase):
class TestTheSuite(unittest.TestCase):
"""A placeholder for unit tests of this Python program"""

def setUp(self):
self.seq = range(10)

def test_exitValueHelperOK(self):
self.assertEqual(helper.exitValue(0), 0)

def test_exitValueHelperError(self):
self.assertEqual(helper.exitValue(-1), 42)

def test_exitValueZero(self):
self.assertEqual(0, 0)

if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 9a41ca0

Please sign in to comment.