summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Liechti <cliechti@gmx.net>2016-06-20 22:52:22 +0200
committerChris Liechti <cliechti@gmx.net>2016-06-20 22:52:22 +0200
commit3debab29c37fd08d2aca481b2bccd1c45f1ceea6 (patch)
treef5c796ecc8a55fea9a4ee2784d69060a554807b5
parent9e60ac771deb58fbfabfd1e3ee258e74265eac7f (diff)
downloadpyserial-git-3debab29c37fd08d2aca481b2bccd1c45f1ceea6.tar.gz
style: use .format() instead of % formatting
-rw-r--r--test/handlers/protocol_test.py16
-rw-r--r--test/run_all_tests.py6
-rw-r--r--test/test.py8
-rw-r--r--test/test_advanced.py2
-rw-r--r--test/test_asyncio.py2
-rw-r--r--test/test_cancel.py2
-rw-r--r--test/test_high_load.py4
-rw-r--r--test/test_iolib.py2
-rw-r--r--test/test_readline.py2
-rw-r--r--test/test_rs485.py2
-rw-r--r--test/test_settings_dict.py2
11 files changed, 24 insertions, 24 deletions
diff --git a/test/handlers/protocol_test.py b/test/handlers/protocol_test.py
index 42ac4b2..f2e572f 100644
--- a/test/handlers/protocol_test.py
+++ b/test/handlers/protocol_test.py
@@ -71,9 +71,9 @@ class DummySerial(SerialBase):
self.logger.setLevel(LOGGER_LEVELS[value])
self.logger.debug('enabled logging')
else:
- raise ValueError('unknown option: %r' % (option,))
+ raise ValueError('unknown option: {!r}'.format(option))
except ValueError as e:
- raise SerialException('expected a string in the form "[test://][option[/option...]]": %s' % e)
+ raise SerialException('expected a string in the form "[test://][option[/option...]]": {}'.format(e))
return (host, port)
# - - - - - - - - - - - - - - - - - - - - - - - -
@@ -120,26 +120,26 @@ class DummySerial(SerialBase):
duration."""
if not self._isOpen: raise portNotOpenError
if self.logger:
- self.logger.info('ignored sendBreak(%r)' % (duration,))
+ self.logger.info('ignored sendBreak({!r})'.format(duration))
def setBreak(self, level=True):
"""Set break: Controls TXD. When active, to transmitting is
possible."""
if not self._isOpen: raise portNotOpenError
if self.logger:
- self.logger.info('ignored setBreak(%r)' % (level,))
+ self.logger.info('ignored setBreak({!r})'.format(level))
def setRTS(self, level=True):
"""Set terminal status line: Request To Send"""
if not self._isOpen: raise portNotOpenError
if self.logger:
- self.logger.info('ignored setRTS(%r)' % (level,))
+ self.logger.info('ignored setRTS({!r})'.format(level))
def setDTR(self, level=True):
"""Set terminal status line: Data Terminal Ready"""
if not self._isOpen: raise portNotOpenError
if self.logger:
- self.logger.info('ignored setDTR(%r)' % (level,))
+ self.logger.info('ignored setDTR({!r})'.format(level))
def getCTS(self):
"""Read terminal status line: Clear To Send"""
@@ -192,11 +192,11 @@ else:
if __name__ == '__main__':
import sys
s = Serial('test://logging=debug')
- sys.stdout.write('%s\n' % s)
+ sys.stdout.write('{}\n'.format(s))
sys.stdout.write("write...\n")
s.write("hello\n")
s.flush()
- sys.stdout.write("read: %s\n" % s.read(5))
+ sys.stdout.write("read: {}\n".format(s.read(5)))
s.close()
diff --git a/test/run_all_tests.py b/test/run_all_tests.py
index 355cd44..c49dc53 100644
--- a/test/run_all_tests.py
+++ b/test/run_all_tests.py
@@ -18,7 +18,7 @@ import os
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
import serial # noqa
-print("Patching sys.path to test local version. Testing Version: %s" % (serial.VERSION,))
+print("Patching sys.path to test local version. Testing Version: {}".format(serial.VERSION))
PORT = 'loop://'
if len(sys.argv) > 1:
@@ -34,11 +34,11 @@ for modulename in [
try:
module = __import__(modulename)
except ImportError:
- print("skipping %s" % (modulename,))
+ print("skipping {}".format(modulename))
else:
module.PORT = PORT
testsuite = unittest.findTestCases(module)
- print("found %s tests in %r" % (testsuite.countTestCases(), modulename))
+ print("found {} tests in {!r}".format(testsuite.countTestCases(), modulename))
mainsuite.addTest(testsuite)
verbosity = 1
diff --git a/test/test.py b/test/test.py
index 8b38c8c..db03907 100644
--- a/test/test.py
+++ b/test/test.py
@@ -66,7 +66,7 @@ class Test4_Nonblocking(unittest.TestCase):
self.s.write(block)
# 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.in_waiting, length, "expected exactly {} character for inWainting()".format(length))
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")
@@ -131,7 +131,7 @@ class Test1_Forever(unittest.TestCase):
a character is sent after some time to terminate the test (SendEvent)."""
c = self.s.read(1)
if not (self.event.isSet() and c == b'E'):
- self.fail("expected marker (evt=%r, c=%r)" % (self.event.isSet(), c))
+ self.fail("expected marker (evt={!r}, c={!r})".format(self.event.isSet(), c))
class Test2_Forever(unittest.TestCase):
@@ -220,14 +220,14 @@ class Test_MoreTimeouts(unittest.TestCase):
t1 = time.time()
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 ({})".format(t2 - t1))
if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_advanced.py b/test/test_advanced.py
index 19559b2..f91baba 100644
--- a/test/test_advanced.py
+++ b/test/test_advanced.py
@@ -179,7 +179,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_asyncio.py b/test/test_asyncio.py
index 99548b3..5df8ef2 100644
--- a/test/test_asyncio.py
+++ b/test/test_asyncio.py
@@ -76,7 +76,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_cancel.py b/test/test_cancel.py
index 210891b..ce030a3 100644
--- a/test/test_cancel.py
+++ b/test/test_cancel.py
@@ -103,7 +103,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_high_load.py b/test/test_high_load.py
index 48ec9f3..78d66a9 100644
--- a/test/test_high_load.py
+++ b/test/test_high_load.py
@@ -61,7 +61,7 @@ class TestHighLoad(unittest.TestCase):
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(read, q * self.N, "expected what was written before. got {} bytes, expected {}".format(len(read), self.N * len(q)))
self.assertEqual(self.s.inWaiting(), 0) # "expected empty buffer after all sent chars are read")
@@ -70,7 +70,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_iolib.py b/test/test_iolib.py
index 71c7db6..3dfaf50 100644
--- a/test/test_iolib.py
+++ b/test/test_iolib.py
@@ -64,7 +64,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_readline.py b/test/test_readline.py
index ac0c813..b23cedd 100644
--- a/test/test_readline.py
+++ b/test/test_readline.py
@@ -98,7 +98,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_rs485.py b/test/test_rs485.py
index 1d7ed09..153b345 100644
--- a/test/test_rs485.py
+++ b/test/test_rs485.py
@@ -59,7 +59,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()
diff --git a/test/test_settings_dict.py b/test/test_settings_dict.py
index 12fd4c3..ac3c533 100644
--- a/test/test_settings_dict.py
+++ b/test/test_settings_dict.py
@@ -74,7 +74,7 @@ if __name__ == '__main__':
sys.stdout.write(__doc__)
if len(sys.argv) > 1:
PORT = sys.argv[1]
- sys.stdout.write("Testing port: %r\n" % PORT)
+ sys.stdout.write("Testing port: {!r}\n".format(PORT))
sys.argv[1:] = ['-v']
# When this module is executed from the command-line, it runs all its tests
unittest.main()