summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChris Liechti <cliechti@gmx.net>2016-02-03 01:22:22 +0100
committerChris Liechti <cliechti@gmx.net>2016-02-03 01:22:22 +0100
commit8e37ba9ee0796195df4f9248989d57c661319bf1 (patch)
treed61df5a22ce770768be4aafec30f9f6c74807e99 /test
parentcb6ce1b7e474131c881e1ed73e9126f651d4a9ea (diff)
downloadpyserial-git-8e37ba9ee0796195df4f9248989d57c661319bf1.tar.gz
style: some of the suggestions from flake8
Diffstat (limited to 'test')
-rw-r--r--test/run_all_tests.py2
-rw-r--r--test/test.py16
-rw-r--r--test/test_advanced.py4
-rw-r--r--test/test_high_load.py10
-rw-r--r--test/test_iolib.py8
-rw-r--r--test/test_readline.py8
-rw-r--r--test/test_rfc2217.py7
-rw-r--r--test/test_rs485.py2
-rw-r--r--test/test_settings_dict.py3
-rw-r--r--test/test_url.py6
10 files changed, 33 insertions, 33 deletions
diff --git a/test/run_all_tests.py b/test/run_all_tests.py
index 39114af..6836d59 100644
--- a/test/run_all_tests.py
+++ b/test/run_all_tests.py
@@ -44,7 +44,7 @@ for modulename in [
verbosity = 1
if '-v' in sys.argv[1:]:
verbosity = 2
- print('-'*78)
+ print('-' * 78)
# run the collected tests
testRunner = unittest.TextTestRunner(verbosity=verbosity)
diff --git a/test/test.py b/test/test.py
index 83f380e..a97eac5 100644
--- a/test/test.py
+++ b/test/test.py
@@ -36,7 +36,7 @@ bytes_0to255 = bytes(bytearray(range(256)))
def segments(data, size=16):
for a in range(0, len(data), size):
- yield data[a:a+size]
+ yield data[a:a + size]
class Test4_Nonblocking(unittest.TestCase):
@@ -67,7 +67,7 @@ class Test4_Nonblocking(unittest.TestCase):
# there might be a small delay until the character is ready (especially on win32)
time.sleep(0.05)
self.assertEqual(self.s.in_waiting, length, "expected exactly %d character for inWainting()" % length)
- self.assertEqual(self.s.read(length), block)#, "expected a %r which was written before" % block)
+ self.assertEqual(self.s.read(length), block) #, "expected a %r which was written before" % block)
self.assertEqual(self.s.read(1), b'', "expected empty buffer after all sent chars are read")
def test2_LoopbackTimeout(self):
@@ -113,6 +113,7 @@ class SendEvent(threading.Thread):
self.stopped = 1
self.x.wait()
+
class Test1_Forever(unittest.TestCase):
"""Tests a port with no timeout. These tests require that a
character is sent after some time to stop the test, this is done
@@ -153,8 +154,8 @@ class Test2_Forever(unittest.TestCase):
self.s.write(block)
# there might be a small delay until the character is ready (especially on win32 and rfc2217)
time.sleep(0.05)
- self.assertEqual(self.s.in_waiting, length)#, "expected exactly %d character for inWainting()" % length)
- self.assertEqual(self.s.read(length), block) #, "expected %r which was written before" % block)
+ self.assertEqual(self.s.in_waiting, length) #, "expected exactly %d character for inWainting()" % length)
+ self.assertEqual(self.s.read(length), block) #, "expected %r which was written before" % block)
self.assertEqual(self.s.in_waiting, 0, "expected empty buffer after all sent chars are read")
@@ -213,15 +214,14 @@ class Test_MoreTimeouts(unittest.TestCase):
self.s.xonxoff = True
self.s.open()
self.s.write(serial.XOFF)
- time.sleep(0.5) # some systems need a little delay so that they can react on XOFF
+ time.sleep(0.5) # some systems need a little delay so that they can react on XOFF
t1 = time.time()
- self.assertRaises(serial.SerialTimeoutException, self.s.write, b"timeout please"*200)
+ self.assertRaises(serial.SerialTimeoutException, self.s.write, b"timeout please" * 200)
t2 = time.time()
- self.assertTrue( 0.9 <= (t2-t1) < 2.1, "Timeout not in the given interval (%s)" % (t2-t1))
+ self.assertTrue(0.9 <= (t2 - t1) < 2.1, "Timeout not in the given interval (%s)" % (t2 - t1))
if __name__ == '__main__':
- import sys
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
diff --git a/test/test_advanced.py b/test/test_advanced.py
index 8f83a40..19559b2 100644
--- a/test/test_advanced.py
+++ b/test/test_advanced.py
@@ -25,6 +25,7 @@ import serial
# on which port should the tests be performed:
PORT = 0
+
class Test_ChangeAttributes(unittest.TestCase):
"""Test with timeouts"""
@@ -70,7 +71,6 @@ class Test_ChangeAttributes(unittest.TestCase):
# calling open for a second time is an error
self.assertRaises(serial.SerialException, self.s.open)
-
def test_BaudrateSetting(self):
self.s.port = PORT
self.s.open()
@@ -94,7 +94,7 @@ class Test_ChangeAttributes(unittest.TestCase):
self.assertRaises(ValueError, setattr, self.s, 'baudrate', illegal_value)
def test_BytesizeSetting(self):
- for bytesize in (5,6,7,8):
+ for bytesize in (5, 6, 7, 8):
self.s.bytesize = bytesize
# test get method
self.assertEqual(self.s.bytesize, bytesize)
diff --git a/test/test_high_load.py b/test/test_high_load.py
index 0138039..48ec9f3 100644
--- a/test/test_high_load.py
+++ b/test/test_high_load.py
@@ -52,17 +52,17 @@ class TestHighLoad(unittest.TestCase):
for i in range(self.N):
q = bytes_0to255
self.s.write(q)
- self.assertEqual(self.s.read(len(q)), q) # expected same which was written before
- self.assertEqual(self.s.inWaiting(), 0) # expected empty buffer after all sent chars are read
+ self.assertEqual(self.s.read(len(q)), q) # expected same which was written before
+ self.assertEqual(self.s.inWaiting(), 0) # expected empty buffer after all sent chars are read
def test1_WriteWriteReadLoopback(self):
"""Send big strings, multiple write one read."""
q = bytes_0to255
for i in range(self.N):
self.s.write(q)
- read = self.s.read(len(q)*self.N)
- self.assertEqual(read, q*self.N, "expected what was written before. got %d bytes, expected %d" % (len(read), self.N*len(q)))
- self.assertEqual(self.s.inWaiting(), 0) # "expected empty buffer after all sent chars are read")
+ read = self.s.read(len(q) * self.N)
+ self.assertEqual(read, q * self.N, "expected what was written before. got %d bytes, expected %d" % (len(read), self.N * len(q)))
+ self.assertEqual(self.s.inWaiting(), 0) # "expected empty buffer after all sent chars are read")
if __name__ == '__main__':
diff --git a/test/test_iolib.py b/test/test_iolib.py
index 43ab797..716eb0d 100644
--- a/test/test_iolib.py
+++ b/test/test_iolib.py
@@ -27,7 +27,7 @@ On a 9 pole DSUB these are the pins (2-3) (4-6) (7-8)
import unittest
import sys
-if __name__ == '__main__' and sys.version_info < (2, 6):
+if __name__ == '__main__' and sys.version_info < (2, 6):
sys.stderr.write("""\
==============================================================================
WARNING: this test is intended for Python 2.6 and newer where the io library
@@ -44,12 +44,14 @@ import serial
# like u'nicode' strings with the prefix and it is not providing an unicode
# function ('str' is now what 'unicode' used to be)
if sys.version_info >= (3, 0):
- def unicode(x): return x
+ def unicode(x):
+ return x
# on which port should the tests be performed:
PORT = 0
+
class Test_SerialAndIO(unittest.TestCase):
def setUp(self):
@@ -62,7 +64,7 @@ class Test_SerialAndIO(unittest.TestCase):
def test_hello_raw(self):
self.io.write(b"hello\n".decode('utf-8'))
- self.io.flush() # it is buffering. required to get the data out
+ self.io.flush() # it is buffering. required to get the data out
hello = self.io.readline()
self.assertEqual(hello, b"hello\n".decode('utf-8'))
diff --git a/test/test_readline.py b/test/test_readline.py
index 1456ac9..ac0c813 100644
--- a/test/test_readline.py
+++ b/test/test_readline.py
@@ -22,8 +22,6 @@ On a 9 pole DSUB these are the pins (2-3) (4-6) (7-8)
"""
import unittest
-import threading
-import time
import sys
import serial
@@ -36,8 +34,8 @@ if sys.version_info >= (3, 0):
def data(string):
return bytes(string, 'latin1')
else:
- def data(string): return string
-
+ def data(string):
+ return string
class Test_Readline(unittest.TestCase):
@@ -88,7 +86,7 @@ class Test_Readline(unittest.TestCase):
def test_alternate_eol(self):
"""Test readline with alternative eol settings (skipped for io based systems)"""
- if hasattr(self.s, 'xreadlines'): # test if it is our FileLike base class
+ if hasattr(self.s, 'xreadlines'): # test if it is our FileLike base class
self.s.write(serial.to_bytes("no\rno\nyes\r\n"))
self.assertEqual(
self.s.readline(eol=serial.to_bytes("\r\n")),
diff --git a/test/test_rfc2217.py b/test/test_rfc2217.py
index 132a1ca..7dbe2a6 100644
--- a/test/test_rfc2217.py
+++ b/test/test_rfc2217.py
@@ -12,6 +12,7 @@ import unittest
import serial
import serial.rfc2217
+
class Test_RFC2217(unittest.TestCase):
"""Test RFC 2217 related functionality"""
@@ -20,16 +21,16 @@ class Test_RFC2217(unittest.TestCase):
s = serial.serial_for_url('rfc2217://127.99.99.99:2217', do_not_open=True)
self.assertRaises(serial.SerialException, s.open)
self.assertFalse(s.is_open)
- s.close() # no errors expected
+ s.close() # no errors expected
# invalid address
s = serial.serial_for_url('rfc2217://127goingtofail', do_not_open=True)
self.assertRaises(serial.SerialException, s.open)
self.assertFalse(s.is_open)
- s.close() # no errors expected
+ s.close() # no errors expected
# close w/o open is also OK
s = serial.serial_for_url('rfc2217://irrelevant', do_not_open=True)
self.assertFalse(s.is_open)
- s.close() # no errors expected
+ s.close() # no errors expected
if __name__ == '__main__':
diff --git a/test/test_rs485.py b/test/test_rs485.py
index 27c0740..1d7ed09 100644
--- a/test/test_rs485.py
+++ b/test/test_rs485.py
@@ -15,6 +15,7 @@ import serial.rs485
# on which port should the tests be performed:
PORT = 0
+
class Test_RS485_settings(unittest.TestCase):
"""Test RS485 related functionality"""
@@ -53,7 +54,6 @@ class Test_RS485_class(unittest.TestCase):
self.assertEqual(self.s.read(5), b'hello')
-
if __name__ == '__main__':
import sys
sys.stdout.write(__doc__)
diff --git a/test/test_settings_dict.py b/test/test_settings_dict.py
index 935c8b6..ae90720 100644
--- a/test/test_settings_dict.py
+++ b/test/test_settings_dict.py
@@ -63,11 +63,12 @@ class Test_SettingsDict(unittest.TestCase):
('rtscts', True),
('dsrdtr', True),
):
- kwargs = {'do_not_open':True, setting:value}
+ kwargs = {'do_not_open': True, setting: value}
ser = serial.serial_for_url(PORT, **kwargs)
d = ser.get_settings()
self.assertEqual(getattr(ser, setting), value)
+
if __name__ == '__main__':
import sys
sys.stdout.write(__doc__)
diff --git a/test/test_url.py b/test/test_url.py
index 926d2a8..e37d3fa 100644
--- a/test/test_url.py
+++ b/test/test_url.py
@@ -15,8 +15,6 @@ Cover some of the aspects of serial_for_url and the extension mechanism.
"""
import unittest
-import time
-import sys
import serial
@@ -25,7 +23,7 @@ class Test_URL(unittest.TestCase):
def test_loop(self):
"""loop interface"""
- s = serial.serial_for_url('loop://', do_not_open=True)
+ serial.serial_for_url('loop://', do_not_open=True)
def test_bad_url(self):
"""invalid protocol specified"""
@@ -38,7 +36,7 @@ class Test_URL(unittest.TestCase):
# add search path
serial.protocol_handler_packages.append('handlers')
# now it should work
- s = serial.serial_for_url("test://")
+ serial.serial_for_url("test://")
# remove our handler again
serial.protocol_handler_packages.remove('handlers')
# so it should not work anymore