aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChris Liechti <cliechti@gmx.net>2015-10-28 00:05:52 +0100
committerChris Liechti <cliechti@gmx.net>2015-10-28 00:05:52 +0100
commit0af3b821141b79998df032bd9bfb77aabc22d58c (patch)
tree14cc781530af5fa4a4a5fd6a08e9dd66d6528828 /test
parent7c032f1d3231636b64c6040830ba00d9fa35306d (diff)
downloadpyserial-0af3b821141b79998df032bd9bfb77aabc22d58c.tar.gz
test_settings_dict: add a new test, refactor, doc
Diffstat (limited to 'test')
-rw-r--r--test/test_settings_dict.py58
1 files changed, 32 insertions, 26 deletions
diff --git a/test/test_settings_dict.py b/test/test_settings_dict.py
index 2640335..e11d24f 100644
--- a/test/test_settings_dict.py
+++ b/test/test_settings_dict.py
@@ -1,22 +1,14 @@
#!/usr/bin/env python
#
# This file is part of pySerial - Cross platform serial port support for Python
-# (C) 2015 Chris Liechti <cliechti@gmx.net>
+# (C) 2002-2015 Chris Liechti <cliechti@gmx.net>
#
# SPDX-License-Identifier: BSD-3-Clause
"""\
Test the ability to get and set the settings with a dictionary.
-Part of pyserial (http://pyserial.sf.net) (C)2002 cliechti@gmx.net
+Part of pySerial (http://pyserial.sf.net) (C) 2002-2015 cliechti@gmx.net
-Intended to be run on different platforms, to ensure portability of
-the code.
-
-These tests open a serial port and change all the settings on the fly.
-If the port is really correctly configured cannot be determined - that
-would require external hardware or a null modem cable and an other
-serial port library... Thus it mainly tests that all features are
-correctly implemented and that the interface does what it should.
"""
import unittest
@@ -31,36 +23,50 @@ SETTINGS = ('baudrate', 'bytesize', 'parity', 'stopbits', 'xonxoff',
class Test_SettingsDict(unittest.TestCase):
- """Test with ettings dictionary"""
-
- def setUp(self):
- # create a closed serial port
- self.s = serial.serial_for_url(PORT, do_not_open=True)
-
- def tearDown(self):
- self.s.close()
+ """Test with settings dictionary"""
def test_getsettings(self):
"""the settings dict reflects the current settings"""
- d = self.s.get_settings()
+ ser = serial.serial_for_url(PORT, do_not_open=True)
+ d = ser.get_settings()
for setting in SETTINGS:
- self.failUnlessEqual(getattr(self.s, setting), d[setting])
+ self.failUnlessEqual(getattr(ser, setting), d[setting])
def test_partial_settings(self):
"""partial settings dictionaries are also accepted"""
- d = self.s.get_settings()
+ ser = serial.serial_for_url(PORT, do_not_open=True)
+ d = ser.get_settings()
del d['baudrate']
del d['bytesize']
- self.s.apply_settings(d)
+ ser.apply_settings(d)
for setting in d:
- self.failUnlessEqual(getattr(self.s, setting), d[setting])
+ self.failUnlessEqual(getattr(ser, setting), d[setting])
def test_unknown_settings(self):
"""unknown settings are ignored"""
- d = self.s.get_settings()
+ ser = serial.serial_for_url(PORT, do_not_open=True)
+ d = ser.get_settings()
d['foobar'] = 'ignore me'
- self.s.apply_settings(d)
-
+ ser.apply_settings(d)
+
+ def test_init_sets_the_correct_attrs(self):
+ """__init__ sets the fields that get_settings reads"""
+ for setting, value in (
+ ('baudrate', 57600),
+ ('timeout', 7),
+ ('write_timeout', 12),
+ ('inter_byte_timeout', 15),
+ ('stopbits', serial.STOPBITS_TWO),
+ ('bytesize', serial.SEVENBITS),
+ ('parity', serial.PARITY_ODD),
+ ('xonxoff', True),
+ ('rtscts', True),
+ ('dsrdtr', True),
+ ):
+ kwargs = {'do_not_open':True, setting:value}
+ ser = serial.serial_for_url(PORT, **kwargs)
+ d = ser.get_settings()
+ self.failUnlessEqual(getattr(ser, setting), value)
if __name__ == '__main__':
import sys