diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2009-07-25 03:44:33 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2009-07-25 03:44:33 +0000 |
commit | 9b12562f15ac2cffc06fada3d19db679ae9bf259 (patch) | |
tree | b9f35aeb97279b707c08080c3b94e6594d82440f /examples | |
parent | fdf8367b8d2d9ced7ccf0349afd476552f6e71ce (diff) | |
download | pyserial-9b12562f15ac2cffc06fada3d19db679ae9bf259.tar.gz |
- add more methods for file-like compatibility
- provide RawSerial when io library is present (not yet finished)
-> changes internal class hierarchy
-> renamed internal read/write -> _read/_write (FileLike resp. RawSerialBase provides read/write)
-> add test_rawio.py
- _write returns number of byte written
- set minimal python version to 2.3 due to basestring
- add "name" attribute
- documentation updates (new io stuff and VERSION, device())
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@249 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'examples')
-rw-r--r-- | examples/test_rawio.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/examples/test_rawio.py b/examples/test_rawio.py new file mode 100644 index 0000000..674934f --- /dev/null +++ b/examples/test_rawio.py @@ -0,0 +1,57 @@ +##! /usr/bin/env python +# Python Serial Port Extension for Win32, Linux, BSD, Jython +# see __init__.py +# +# (C) 2001-2008 Chris Liechti <cliechti@gmx.net> +# this is distributed under a free software license, see license.txt + +"""\ +Some tests for the serial module. +Part of pyserial (http://pyserial.sf.net) (C)2001-2009 cliechti@gmx.net + +Intended to be run on different platforms, to ensure portability of +the code. + +This modules contains test for RawSerial. This only works on Python 2.6+ with +the io library. + +For all these tests a simple hardware is required. +Loopback HW adapter: +Shortcut these pin pairs: + TX <-> RX + RTS <-> CTS + DTR <-> DSR + +On a 9 pole DSUB these are the pins (2-3) (4-6) (7-8) +""" + +import unittest, threading, time +import serial + +# on which port should the tests be performed: +PORT=0 + +class Test_RawSerial(unittest.TestCase): + + def setUp(self): + self.s = serial.RawSerial(PORT) + + def tearDown(self): + self.s.close() + + def test_hello(self): + self.s.write(bytes("hello")) + hello = self.s.read(5) + #~ print hello + self.failUnlessEqual(hello, bytes("hello")) + + +if __name__ == '__main__': + import sys + sys.stdout.write(__doc__) + if len(sys.argv) > 1: + PORT = sys.argv[1] + sys.stdout.write("Testing port: %r\n" % PORT) + sys.argv[1:] = ['-v'] + # When this module is executed from the command-line, it runs all its tests + unittest.main() |