From 4c6959cdfea55c82de2370f95af7b6d0b1a70598 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 19 Jan 2024 20:13:26 +0100 Subject: [PATCH] rename package serial -> serial_labgrid labgrid's pyserial fork uses the same package name as the original pyserial. This becomes a problem once another dependency pulls in the original pyserial. Then one package will overwrite the other. Thus, rename the package from "serial" to "serial_labgrid": - pyproject.toml edited manually - `pip install rope`, then run: ``` import rope project = rope.base.project.Project(".") serial = project.find_module("serial") changes = rope.refactor.rename.Rename(project, serial).get_changes("serial_labgrid") project.do(changes) ``` - update serial.urlhandler -> serial_labgrid.urlhandler in serial_labgrid/__init__.py:protocol_handler_packages Signed-off-by: Bastian Krause --- examples/at_protocol.py | 10 ++--- examples/port_publisher.py | 16 ++++---- examples/rfc2217_server.py | 10 ++--- examples/setup-miniterm-py2exe.py | 4 +- examples/tcp_serial_redirect.py | 12 +++--- examples/wxSerialConfigDialog.py | 10 ++--- examples/wxTerminal.py | 8 ++-- pyproject.toml | 12 +++--- {serial => serial_labgrid}/__init__.py | 12 +++--- {serial => serial_labgrid}/__main__.py | 0 {serial => serial_labgrid}/rfc2217.py | 20 +++++----- {serial => serial_labgrid}/rs485.py | 4 +- {serial => serial_labgrid}/serialcli.py | 2 +- {serial => serial_labgrid}/serialjava.py | 2 +- {serial => serial_labgrid}/serialposix.py | 22 +++++----- {serial => serial_labgrid}/serialutil.py | 0 {serial => serial_labgrid}/serialwin32.py | 36 ++++++++--------- .../threaded/__init__.py | 10 ++--- {serial => serial_labgrid}/tools/__init__.py | 0 .../tools/hexlify_codec.py | 14 +++---- .../tools/list_ports.py | 4 +- .../tools/list_ports_common.py | 0 .../tools/list_ports_linux.py | 2 +- .../tools/list_ports_osx.py | 2 +- .../tools/list_ports_posix.py | 10 ++--- .../tools/list_ports_windows.py | 6 +-- {serial => serial_labgrid}/tools/miniterm.py | 40 +++++++++---------- .../urlhandler/__init__.py | 0 .../urlhandler/protocol_alt.py | 14 +++---- .../urlhandler/protocol_cp2110.py | 20 +++++----- .../urlhandler/protocol_hwgrep.py | 20 +++++----- .../urlhandler/protocol_loop.py | 2 +- .../urlhandler/protocol_rfc2217.py | 2 +- .../urlhandler/protocol_socket.py | 2 +- .../urlhandler/protocol_spy.py | 40 +++++++++---------- {serial => serial_labgrid}/win32.py | 0 test/handlers/protocol_test.py | 2 +- test/run_all_tests.py | 4 +- test/test.py | 16 ++++---- test/test_advanced.py | 10 ++--- test/test_asyncio.py | 6 +-- test/test_cancel.py | 10 ++--- test/test_context.py | 4 +- test/test_exclusive.py | 18 ++++----- test/test_high_load.py | 4 +- test/test_iolib.py | 4 +- test/test_pty.py | 8 ++-- test/test_readline.py | 32 +++++++-------- test/test_rfc2217.py | 14 +++---- test/test_rs485.py | 14 +++---- test/test_settings_dict.py | 16 ++++---- test/test_threaded.py | 16 ++++---- test/test_timeout_class.py | 2 +- test/test_url.py | 16 ++++---- test/test_util.py | 12 +++--- 55 files changed, 288 insertions(+), 288 deletions(-) rename {serial => serial_labgrid}/__init__.py (90%) rename {serial => serial_labgrid}/__main__.py (100%) rename {serial => serial_labgrid}/rfc2217.py (99%) rename {serial => serial_labgrid}/rs485.py (98%) rename {serial => serial_labgrid}/serialcli.py (99%) rename {serial => serial_labgrid}/serialjava.py (99%) rename {serial => serial_labgrid}/serialposix.py (98%) rename {serial => serial_labgrid}/serialutil.py (100%) rename {serial => serial_labgrid}/serialwin32.py (94%) rename {serial => serial_labgrid}/threaded/__init__.py (97%) rename {serial => serial_labgrid}/tools/__init__.py (100%) rename {serial => serial_labgrid}/tools/hexlify_codec.py (90%) rename {serial => serial_labgrid}/tools/list_ports.py (96%) rename {serial => serial_labgrid}/tools/list_ports_common.py (100%) rename {serial => serial_labgrid}/tools/list_ports_linux.py (98%) rename {serial => serial_labgrid}/tools/list_ports_osx.py (99%) rename {serial => serial_labgrid}/tools/list_ports_posix.py (94%) rename {serial => serial_labgrid}/tools/list_ports_windows.py (99%) rename {serial => serial_labgrid}/tools/miniterm.py (96%) rename {serial => serial_labgrid}/urlhandler/__init__.py (100%) rename {serial => serial_labgrid}/urlhandler/protocol_alt.py (83%) rename {serial => serial_labgrid}/urlhandler/protocol_cp2110.py (93%) rename {serial => serial_labgrid}/urlhandler/protocol_hwgrep.py (82%) rename {serial => serial_labgrid}/urlhandler/protocol_loop.py (98%) rename {serial => serial_labgrid}/urlhandler/protocol_rfc2217.py (84%) rename {serial => serial_labgrid}/urlhandler/protocol_socket.py (99%) rename {serial => serial_labgrid}/urlhandler/protocol_spy.py (90%) rename {serial => serial_labgrid}/win32.py (100%) diff --git a/examples/at_protocol.py b/examples/at_protocol.py index 7d43007d..e490047e 100644 --- a/examples/at_protocol.py +++ b/examples/at_protocol.py @@ -12,8 +12,8 @@ sys.path.insert(0, '..') import logging -import serial -import serial.threaded +import serial_labgrid +import serial_labgrid.threaded import threading try: @@ -26,7 +26,7 @@ class ATException(Exception): pass -class ATProtocol(serial.threaded.LineReader): +class ATProtocol(serial_labgrid.threaded.LineReader): TERMINATOR = b'\r\n' @@ -146,9 +146,9 @@ def get_mac_address(self): # requests hardware / calibration info as event return self.command_with_event_response("AT+JRBD") - ser = serial.serial_for_url('spy://COM1', baudrate=115200, timeout=1) + ser = serial_labgrid.serial_for_url('spy://COM1', baudrate=115200, timeout=1) #~ ser = serial.Serial('COM1', baudrate=115200, timeout=1) - with serial.threaded.ReaderThread(ser, PAN1322) as bt_module: + with serial_labgrid.threaded.ReaderThread(ser, PAN1322) as bt_module: bt_module.reset() print("reset OK") print("MAC address is", bt_module.get_mac_address()) diff --git a/examples/port_publisher.py b/examples/port_publisher.py index eecc2a11..2676e0ed 100755 --- a/examples/port_publisher.py +++ b/examples/port_publisher.py @@ -20,9 +20,9 @@ import time import traceback -import serial -import serial.rfc2217 -import serial.tools.list_ports +import serial_labgrid +import serial_labgrid.rfc2217 +import serial_labgrid.tools.list_ports import dbus @@ -105,7 +105,7 @@ def __init__(self, device, name, network_port, on_close=None, log=None): self.on_close = on_close self.log = log self.device = device - self.serial = serial.Serial() + self.serial = serial_labgrid.Serial() self.serial.port = device self.serial.baudrate = 115200 self.serial.timeout = 0 @@ -220,7 +220,7 @@ def handle_serial_read(self): if self.socket is not None: # escape outgoing data when needed (Telnet IAC (0xff) character) if self.rfc2217: - data = serial.to_bytes(self.rfc2217.escape(data)) + data = serial_labgrid.to_bytes(self.rfc2217.escape(data)) self.buffer_ser2net.extend(data) else: self.handle_serial_error() @@ -299,9 +299,9 @@ def handle_connect(self): self.serial.rts = True self.serial.dtr = True if self.log is not None: - self.rfc2217 = serial.rfc2217.PortManager(self.serial, self, logger=log.getChild(self.device)) + self.rfc2217 = serial_labgrid.rfc2217.PortManager(self.serial, self, logger=log.getChild(self.device)) else: - self.rfc2217 = serial.rfc2217.PortManager(self.serial, self) + self.rfc2217 = serial_labgrid.rfc2217.PortManager(self.serial, self) else: # reject connection if there is already one connection.close() @@ -527,7 +527,7 @@ def unpublish(forwarder): now = time.time() if now > next_check: next_check = now + 5 - connected = [d for d, p, i in serial.tools.list_ports.grep(args.ports_regex)] + connected = [d for d, p, i in serial_labgrid.tools.list_ports.grep(args.ports_regex)] # Handle devices that are published, but no longer connected for device in set(published).difference(connected): log.info("unpublish: {}".format(published[device])) diff --git a/examples/rfc2217_server.py b/examples/rfc2217_server.py index 42660dd3..90486fc2 100755 --- a/examples/rfc2217_server.py +++ b/examples/rfc2217_server.py @@ -12,8 +12,8 @@ import sys import time import threading -import serial -import serial.rfc2217 +import serial_labgrid +import serial_labgrid.rfc2217 class Redirector(object): @@ -21,7 +21,7 @@ def __init__(self, serial_instance, socket, debug=False): self.serial = serial_instance self.socket = socket self._write_lock = threading.Lock() - self.rfc2217 = serial.rfc2217.PortManager( + self.rfc2217 = serial_labgrid.rfc2217.PortManager( self.serial, self, logger=logging.getLogger('rfc2217.server') if debug else None) @@ -134,7 +134,7 @@ def stop(self): logging.getLogger('rfc2217').setLevel(level) # connect to serial port - ser = serial.serial_for_url(args.SERIALPORT, do_not_open=True) + ser = serial_labgrid.serial_for_url(args.SERIALPORT, do_not_open=True) ser.timeout = 3 # required so that the reader thread can exit # reset control line as no _remote_ "terminal" has been connected yet ser.dtr = False @@ -144,7 +144,7 @@ def stop(self): try: ser.open() - except serial.SerialException as e: + except serial_labgrid.SerialException as e: logging.error("Could not open serial port {}: {}".format(ser.name, e)) sys.exit(1) diff --git a/examples/setup-miniterm-py2exe.py b/examples/setup-miniterm-py2exe.py index 50ea0c33..edf89a6e 100644 --- a/examples/setup-miniterm-py2exe.py +++ b/examples/setup-miniterm-py2exe.py @@ -9,7 +9,7 @@ sys.path.insert(0, '..') -import serial.tools.miniterm +import serial_labgrid.tools.miniterm sys.argv.extend("py2exe --bundle 1".split()) @@ -28,6 +28,6 @@ } }, console=[ - serial.tools.miniterm.__file__ + serial_labgrid.tools.miniterm.__file__ ], ) diff --git a/examples/tcp_serial_redirect.py b/examples/tcp_serial_redirect.py index bd7db778..522516eb 100755 --- a/examples/tcp_serial_redirect.py +++ b/examples/tcp_serial_redirect.py @@ -8,12 +8,12 @@ import sys import socket -import serial -import serial.threaded +import serial_labgrid +import serial_labgrid.threaded import time -class SerialToNet(serial.threaded.Protocol): +class SerialToNet(serial_labgrid.threaded.Protocol): """serial->socket""" def __init__(self): @@ -129,7 +129,7 @@ def data_received(self, data): args = parser.parse_args() # connect to serial port - ser = serial.serial_for_url(args.SERIALPORT, do_not_open=True) + ser = serial_labgrid.serial_for_url(args.SERIALPORT, do_not_open=True) ser.baudrate = args.BAUDRATE ser.bytesize = args.bytesize ser.parity = args.parity @@ -150,12 +150,12 @@ def data_received(self, data): try: ser.open() - except serial.SerialException as e: + except serial_labgrid.SerialException as e: sys.stderr.write('Could not open serial port {}: {}\n'.format(ser.name, e)) sys.exit(1) ser_to_net = SerialToNet() - serial_worker = serial.threaded.ReaderThread(ser, ser_to_net) + serial_worker = serial_labgrid.threaded.ReaderThread(ser, ser_to_net) serial_worker.start() if not args.client: diff --git a/examples/wxSerialConfigDialog.py b/examples/wxSerialConfigDialog.py index 1901d77a..a04bc6fc 100755 --- a/examples/wxSerialConfigDialog.py +++ b/examples/wxSerialConfigDialog.py @@ -8,8 +8,8 @@ # SPDX-License-Identifier: BSD-3-Clause import wx -import serial -import serial.tools.list_ports +import serial_labgrid +import serial_labgrid.tools.list_ports SHOW_BAUDRATE = 1 << 0 SHOW_FORMAT = 1 << 1 @@ -98,7 +98,7 @@ def __set_properties(self): preferred_index = 0 self.choice_port.Clear() self.ports = [] - for n, (portname, desc, hwid) in enumerate(sorted(serial.tools.list_ports.comports())): + for n, (portname, desc, hwid) in enumerate(sorted(serial_labgrid.tools.list_ports.comports())): self.choice_port.Append(u'{} - {}'.format(portname, desc)) self.ports.append(portname) if self.serial.name == portname: @@ -134,7 +134,7 @@ def __set_properties(self): # fill in parities and select current setting self.choice_parity.Clear() for n, parity in enumerate(self.serial.PARITIES): - self.choice_parity.Append(str(serial.PARITY_NAMES[parity])) + self.choice_parity.Append(str(serial_labgrid.PARITY_NAMES[parity])) if self.serial.parity == parity: index = n self.choice_parity.SetSelection(index) @@ -264,7 +264,7 @@ class MyApp(wx.App): def OnInit(self): wx.InitAllImageHandlers() - ser = serial.Serial() + ser = serial_labgrid.Serial() print(ser) # loop until cancel is pressed, old values are used as start for the next run # show the different views, one after the other diff --git a/examples/wxTerminal.py b/examples/wxTerminal.py index 64768a97..a6c120f4 100755 --- a/examples/wxTerminal.py +++ b/examples/wxTerminal.py @@ -7,8 +7,8 @@ # SPDX-License-Identifier: BSD-3-Clause import codecs -from serial.tools.miniterm import unichr -import serial +from serial_labgrid.tools.miniterm import unichr +import serial_labgrid import threading import wx import wx.lib.newevent @@ -125,7 +125,7 @@ class TerminalFrame(wx.Frame): """Simple terminal program for wxPython""" def __init__(self, *args, **kwds): - self.serial = serial.Serial() + self.serial = serial_labgrid.Serial() self.serial.timeout = 0.5 # make sure that the alive event can be checked from time to time self.settings = TerminalSetup() # placeholder for the settings self.thread = None @@ -265,7 +265,7 @@ def OnPortSettings(self, event): # wxGlade: TerminalFrame. if result == wx.ID_OK or event is not None: try: self.serial.open() - except serial.SerialException as e: + except serial_labgrid.SerialException as e: with wx.MessageDialog(self, str(e), "Serial Port Error", wx.OK | wx.ICON_ERROR)as dlg: dlg.ShowModal() else: diff --git a/pyproject.toml b/pyproject.toml index fe0ffda2..2c3d115d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,16 +27,16 @@ local_scheme = "no-local-version" "Bug Tracker" = "https://github.com/labgrid-project/labgrid/issues" [project.scripts] -pyserial-miniterm = "serial.tools.miniterm:main" -pyserial-ports = "serial.tools.list_ports:main" +pyserial-miniterm = "serial_labgrid.tools.miniterm:main" +pyserial-ports = "serial_labgrid.tools.list_ports:main" [project.optional-dependencies] cp2110 = ['hidapi'] [tool.setuptools] packages = [ - "serial", - "serial.threaded", - "serial.tools", - "serial.urlhandler", + "serial_labgrid", + "serial_labgrid.threaded", + "serial_labgrid.tools", + "serial_labgrid.urlhandler", ] diff --git a/serial/__init__.py b/serial_labgrid/__init__.py similarity index 90% rename from serial/__init__.py rename to serial_labgrid/__init__.py index 65341277..1435b988 100644 --- a/serial/__init__.py +++ b/serial_labgrid/__init__.py @@ -12,7 +12,7 @@ import sys import importlib -from serial.serialutil import * +from serial_labgrid.serialutil import * #~ SerialBase, SerialException, to_bytes, iterbytes __version__ = '3.5.0.2' @@ -21,22 +21,22 @@ # pylint: disable=wrong-import-position if sys.platform == 'cli': - from serial.serialcli import Serial + from serial_labgrid.serialcli import Serial else: import os # chose an implementation, depending on os if os.name == 'nt': # sys.platform == 'win32': - from serial.serialwin32 import Serial + from serial_labgrid.serialwin32 import Serial elif os.name == 'posix': - from serial.serialposix import Serial, PosixPollSerial, VTIMESerial # noqa + from serial_labgrid.serialposix import Serial, PosixPollSerial, VTIMESerial # noqa elif os.name == 'java': - from serial.serialjava import Serial + from serial_labgrid.serialjava import Serial else: raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name)) protocol_handler_packages = [ - 'serial.urlhandler', + 'serial_labgrid.urlhandler', ] diff --git a/serial/__main__.py b/serial_labgrid/__main__.py similarity index 100% rename from serial/__main__.py rename to serial_labgrid/__main__.py diff --git a/serial/rfc2217.py b/serial_labgrid/rfc2217.py similarity index 99% rename from serial/rfc2217.py rename to serial_labgrid/rfc2217.py index 081ed2a1..f34bd0ab 100644 --- a/serial/rfc2217.py +++ b/serial_labgrid/rfc2217.py @@ -74,8 +74,8 @@ except ImportError: import queue as Queue -import serial -from serial.serialutil import SerialBase, SerialException, to_bytes, \ +import serial_labgrid +from serial_labgrid.serialutil import SerialBase, SerialException, to_bytes, \ iterbytes, PortNotOpenError, Timeout # port string is expected to be something like this: @@ -207,18 +207,18 @@ RFC2217_PARITY_MAP = { - serial.PARITY_NONE: 1, - serial.PARITY_ODD: 2, - serial.PARITY_EVEN: 3, - serial.PARITY_MARK: 4, - serial.PARITY_SPACE: 5, + serial_labgrid.PARITY_NONE: 1, + serial_labgrid.PARITY_ODD: 2, + serial_labgrid.PARITY_EVEN: 3, + serial_labgrid.PARITY_MARK: 4, + serial_labgrid.PARITY_SPACE: 5, } RFC2217_REVERSE_PARITY_MAP = dict((v, k) for k, v in RFC2217_PARITY_MAP.items()) RFC2217_STOPBIT_MAP = { - serial.STOPBITS_ONE: 1, - serial.STOPBITS_ONE_POINT_FIVE: 3, - serial.STOPBITS_TWO: 2, + serial_labgrid.STOPBITS_ONE: 1, + serial_labgrid.STOPBITS_ONE_POINT_FIVE: 3, + serial_labgrid.STOPBITS_TWO: 2, } RFC2217_REVERSE_STOPBIT_MAP = dict((v, k) for k, v in RFC2217_STOPBIT_MAP.items()) diff --git a/serial/rs485.py b/serial_labgrid/rs485.py similarity index 98% rename from serial/rs485.py rename to serial_labgrid/rs485.py index d7aff6f6..2c38bbc4 100644 --- a/serial/rs485.py +++ b/serial_labgrid/rs485.py @@ -16,7 +16,7 @@ from __future__ import absolute_import import time -import serial +import serial_labgrid class RS485Settings(object): @@ -34,7 +34,7 @@ def __init__( self.delay_before_rx = delay_before_rx -class RS485(serial.Serial): +class RS485(serial_labgrid.Serial): """\ A subclass that replaces the write method with one that toggles RTS according to the RS485 settings. diff --git a/serial/serialcli.py b/serial_labgrid/serialcli.py similarity index 99% rename from serial/serialcli.py rename to serial_labgrid/serialcli.py index 4614736e..5676d591 100644 --- a/serial/serialcli.py +++ b/serial_labgrid/serialcli.py @@ -11,7 +11,7 @@ import System import System.IO.Ports -from serial.serialutil import * +from serial_labgrid.serialutil import * # must invoke function with byte array, make a helper to convert strings # to byte arrays diff --git a/serial/serialjava.py b/serial_labgrid/serialjava.py similarity index 99% rename from serial/serialjava.py rename to serial_labgrid/serialjava.py index 0789a780..33abf96f 100644 --- a/serial/serialjava.py +++ b/serial_labgrid/serialjava.py @@ -9,7 +9,7 @@ from __future__ import absolute_import -from serial.serialutil import * +from serial_labgrid.serialutil import * def my_import(name): diff --git a/serial/serialposix.py b/serial_labgrid/serialposix.py similarity index 98% rename from serial/serialposix.py rename to serial_labgrid/serialposix.py index 7aceb76d..aa477722 100644 --- a/serial/serialposix.py +++ b/serial_labgrid/serialposix.py @@ -37,8 +37,8 @@ import sys import termios -import serial -from serial.serialutil import SerialBase, SerialException, to_bytes, \ +import serial_labgrid +from serial_labgrid.serialutil import SerialBase, SerialException, to_bytes, \ PortNotOpenError, SerialTimeoutException, Timeout @@ -453,27 +453,27 @@ def _reconfigure_port(self, force_update=False): else: raise ValueError('Invalid char len: {!r}'.format(self._bytesize)) # setup stop bits - if self._stopbits == serial.STOPBITS_ONE: + if self._stopbits == serial_labgrid.STOPBITS_ONE: cflag &= ~(termios.CSTOPB) - elif self._stopbits == serial.STOPBITS_ONE_POINT_FIVE: + elif self._stopbits == serial_labgrid.STOPBITS_ONE_POINT_FIVE: cflag |= (termios.CSTOPB) # XXX same as TWO.. there is no POSIX support for 1.5 - elif self._stopbits == serial.STOPBITS_TWO: + elif self._stopbits == serial_labgrid.STOPBITS_TWO: cflag |= (termios.CSTOPB) else: raise ValueError('Invalid stop bit specification: {!r}'.format(self._stopbits)) # setup parity iflag &= ~(termios.INPCK | termios.ISTRIP) - if self._parity == serial.PARITY_NONE: + if self._parity == serial_labgrid.PARITY_NONE: cflag &= ~(termios.PARENB | termios.PARODD | CMSPAR) - elif self._parity == serial.PARITY_EVEN: + elif self._parity == serial_labgrid.PARITY_EVEN: cflag &= ~(termios.PARODD | CMSPAR) cflag |= (termios.PARENB) - elif self._parity == serial.PARITY_ODD: + elif self._parity == serial_labgrid.PARITY_ODD: cflag &= ~CMSPAR cflag |= (termios.PARENB | termios.PARODD) - elif self._parity == serial.PARITY_MARK and CMSPAR: + elif self._parity == serial_labgrid.PARITY_MARK and CMSPAR: cflag |= (termios.PARENB | CMSPAR | termios.PARODD) - elif self._parity == serial.PARITY_SPACE and CMSPAR: + elif self._parity == serial_labgrid.PARITY_SPACE and CMSPAR: cflag |= (termios.PARENB | CMSPAR) cflag &= ~(termios.PARODD) else: @@ -868,7 +868,7 @@ def _reconfigure_port(self, force_update=True): orig_attr = termios.tcgetattr(self.fd) iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr except termios.error as msg: # if a port is nonexistent but has a /dev file, it'll fail here - raise serial.SerialException("Could not configure port: {}".format(msg)) + raise serial_labgrid.SerialException("Could not configure port: {}".format(msg)) if vtime < 0 or vtime > 255: raise ValueError('Invalid vtime: {!r}'.format(vtime)) diff --git a/serial/serialutil.py b/serial_labgrid/serialutil.py similarity index 100% rename from serial/serialutil.py rename to serial_labgrid/serialutil.py diff --git a/serial/serialwin32.py b/serial_labgrid/serialwin32.py similarity index 94% rename from serial/serialwin32.py rename to serial_labgrid/serialwin32.py index e7da929a..7857f086 100644 --- a/serial/serialwin32.py +++ b/serial_labgrid/serialwin32.py @@ -14,10 +14,10 @@ # pylint: disable=invalid-name,too-few-public-methods import ctypes import time -from serial import win32 +from serial_labgrid import win32 -import serial -from serial.serialutil import SerialBase, SerialException, to_bytes, PortNotOpenError, SerialTimeoutException +import serial_labgrid +from serial_labgrid.serialutil import SerialBase, SerialException, to_bytes, PortNotOpenError, SerialTimeoutException class Serial(SerialBase): @@ -133,40 +133,40 @@ def _reconfigure_port(self): win32.GetCommState(self._port_handle, ctypes.byref(comDCB)) comDCB.BaudRate = self._baudrate - if self._bytesize == serial.FIVEBITS: + if self._bytesize == serial_labgrid.FIVEBITS: comDCB.ByteSize = 5 - elif self._bytesize == serial.SIXBITS: + elif self._bytesize == serial_labgrid.SIXBITS: comDCB.ByteSize = 6 - elif self._bytesize == serial.SEVENBITS: + elif self._bytesize == serial_labgrid.SEVENBITS: comDCB.ByteSize = 7 - elif self._bytesize == serial.EIGHTBITS: + elif self._bytesize == serial_labgrid.EIGHTBITS: comDCB.ByteSize = 8 else: raise ValueError("Unsupported number of data bits: {!r}".format(self._bytesize)) - if self._parity == serial.PARITY_NONE: + if self._parity == serial_labgrid.PARITY_NONE: comDCB.Parity = win32.NOPARITY comDCB.fParity = 0 # Disable Parity Check - elif self._parity == serial.PARITY_EVEN: + elif self._parity == serial_labgrid.PARITY_EVEN: comDCB.Parity = win32.EVENPARITY comDCB.fParity = 1 # Enable Parity Check - elif self._parity == serial.PARITY_ODD: + elif self._parity == serial_labgrid.PARITY_ODD: comDCB.Parity = win32.ODDPARITY comDCB.fParity = 1 # Enable Parity Check - elif self._parity == serial.PARITY_MARK: + elif self._parity == serial_labgrid.PARITY_MARK: comDCB.Parity = win32.MARKPARITY comDCB.fParity = 1 # Enable Parity Check - elif self._parity == serial.PARITY_SPACE: + elif self._parity == serial_labgrid.PARITY_SPACE: comDCB.Parity = win32.SPACEPARITY comDCB.fParity = 1 # Enable Parity Check else: raise ValueError("Unsupported parity mode: {!r}".format(self._parity)) - if self._stopbits == serial.STOPBITS_ONE: + if self._stopbits == serial_labgrid.STOPBITS_ONE: comDCB.StopBits = win32.ONESTOPBIT - elif self._stopbits == serial.STOPBITS_ONE_POINT_FIVE: + elif self._stopbits == serial_labgrid.STOPBITS_ONE_POINT_FIVE: comDCB.StopBits = win32.ONE5STOPBITS - elif self._stopbits == serial.STOPBITS_TWO: + elif self._stopbits == serial_labgrid.STOPBITS_TWO: comDCB.StopBits = win32.TWOSTOPBITS else: raise ValueError("Unsupported number of stop bits: {!r}".format(self._stopbits)) @@ -215,8 +215,8 @@ def _reconfigure_port(self): comDCB.fNull = 0 comDCB.fErrorChar = 0 comDCB.fAbortOnError = 0 - comDCB.XonChar = serial.XON - comDCB.XoffChar = serial.XOFF + comDCB.XonChar = serial_labgrid.XON + comDCB.XoffChar = serial_labgrid.XOFF if not win32.SetCommState(self._port_handle, ctypes.byref(comDCB)): raise SerialException( @@ -474,4 +474,4 @@ def exclusive(self, exclusive): if exclusive is not None and not exclusive: raise ValueError('win32 only supports exclusive access (not: {})'.format(exclusive)) else: - serial.SerialBase.exclusive.__set__(self, exclusive) + serial_labgrid.SerialBase.exclusive.__set__(self, exclusive) diff --git a/serial/threaded/__init__.py b/serial_labgrid/threaded/__init__.py similarity index 97% rename from serial/threaded/__init__.py rename to serial_labgrid/threaded/__init__.py index b8940b6d..d25ee77f 100644 --- a/serial/threaded/__init__.py +++ b/serial_labgrid/threaded/__init__.py @@ -11,7 +11,7 @@ """ from __future__ import absolute_import -import serial +import serial_labgrid import threading @@ -99,7 +99,7 @@ def connection_lost(self, exc): def data_received(self, data): """Find data enclosed in START/STOP, call handle_packet""" - for byte in serial.iterbytes(data): + for byte in serial_labgrid.iterbytes(data): if byte == self.START: self.in_packet = True elif byte == self.STOP: @@ -196,7 +196,7 @@ def run(self): try: # read all that is there or wait for one byte (blocking) data = self.serial.read(self.serial.in_waiting or 1) - except serial.SerialException as e: + except serial_labgrid.SerialException as e: # probably some I/O problem such as disconnected USB serial # adapters -> exit error = e @@ -282,13 +282,13 @@ def connection_lost(self, exc): traceback.print_exc(exc) sys.stdout.write('port closed\n') - ser = serial.serial_for_url(PORT, baudrate=115200, timeout=1) + ser = serial_labgrid.serial_for_url(PORT, baudrate=115200, timeout=1) with ReaderThread(ser, PrintLines) as protocol: protocol.write_line('hello') time.sleep(2) # alternative usage - ser = serial.serial_for_url(PORT, baudrate=115200, timeout=1) + ser = serial_labgrid.serial_for_url(PORT, baudrate=115200, timeout=1) t = ReaderThread(ser, PrintLines) t.start() transport, protocol = t.connect() diff --git a/serial/tools/__init__.py b/serial_labgrid/tools/__init__.py similarity index 100% rename from serial/tools/__init__.py rename to serial_labgrid/tools/__init__.py diff --git a/serial/tools/hexlify_codec.py b/serial_labgrid/tools/hexlify_codec.py similarity index 90% rename from serial/tools/hexlify_codec.py rename to serial_labgrid/tools/hexlify_codec.py index bd8f6b0d..45a1d854 100644 --- a/serial/tools/hexlify_codec.py +++ b/serial_labgrid/tools/hexlify_codec.py @@ -21,7 +21,7 @@ from __future__ import absolute_import import codecs -import serial +import serial_labgrid try: @@ -37,22 +37,22 @@ def hex_encode(data, errors='strict'): """'40 41 42' -> b'@ab'""" - return (serial.to_bytes([int(h, 16) for h in data.split()]), len(data)) + return (serial_labgrid.to_bytes([int(h, 16) for h in data.split()]), len(data)) def hex_decode(data, errors='strict'): """b'@ab' -> '40 41 42'""" - return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))), len(data)) + return (unicode(''.join('{:02X} '.format(ord(b)) for b in serial_labgrid.iterbytes(data))), len(data)) class Codec(codecs.Codec): def encode(self, data, errors='strict'): """'40 41 42' -> b'@ab'""" - return serial.to_bytes([int(h, 16) for h in data.split()]) + return serial_labgrid.to_bytes([int(h, 16) for h in data.split()]) def decode(self, data, errors='strict'): """b'@ab' -> '40 41 42'""" - return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))) + return unicode(''.join('{:02X} '.format(ord(b)) for b in serial_labgrid.iterbytes(data))) class IncrementalEncoder(codecs.IncrementalEncoder): @@ -95,13 +95,13 @@ def encode(self, data, final=False): if self.errors == 'strict': raise UnicodeError('non-hex digit found: {!r}'.format(c)) self.state = state - return serial.to_bytes(encoded) + return serial_labgrid.to_bytes(encoded) class IncrementalDecoder(codecs.IncrementalDecoder): """Incremental decoder""" def decode(self, data, final=False): - return unicode(''.join('{:02X} '.format(ord(b)) for b in serial.iterbytes(data))) + return unicode(''.join('{:02X} '.format(ord(b)) for b in serial_labgrid.iterbytes(data))) class StreamWriter(Codec, codecs.StreamWriter): diff --git a/serial/tools/list_ports.py b/serial_labgrid/tools/list_ports.py similarity index 96% rename from serial/tools/list_ports.py rename to serial_labgrid/tools/list_ports.py index 0d7e3d41..c58685b8 100644 --- a/serial/tools/list_ports.py +++ b/serial_labgrid/tools/list_ports.py @@ -26,9 +26,9 @@ #~ if sys.platform == 'cli': #~ else: if os.name == 'nt': # sys.platform == 'win32': - from serial.tools.list_ports_windows import comports + from serial_labgrid.tools.list_ports_windows import comports elif os.name == 'posix': - from serial.tools.list_ports_posix import comports + from serial_labgrid.tools.list_ports_posix import comports #~ elif os.name == 'java': else: raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name)) diff --git a/serial/tools/list_ports_common.py b/serial_labgrid/tools/list_ports_common.py similarity index 100% rename from serial/tools/list_ports_common.py rename to serial_labgrid/tools/list_ports_common.py diff --git a/serial/tools/list_ports_linux.py b/serial_labgrid/tools/list_ports_linux.py similarity index 98% rename from serial/tools/list_ports_linux.py rename to serial_labgrid/tools/list_ports_linux.py index c8c1cfc0..9002c384 100644 --- a/serial/tools/list_ports_linux.py +++ b/serial_labgrid/tools/list_ports_linux.py @@ -12,7 +12,7 @@ import glob import os -from serial.tools import list_ports_common +from serial_labgrid.tools import list_ports_common class SysFS(list_ports_common.ListPortInfo): diff --git a/serial/tools/list_ports_osx.py b/serial_labgrid/tools/list_ports_osx.py similarity index 99% rename from serial/tools/list_ports_osx.py rename to serial_labgrid/tools/list_ports_osx.py index 51b4e8c0..0870892b 100644 --- a/serial/tools/list_ports_osx.py +++ b/serial_labgrid/tools/list_ports_osx.py @@ -25,7 +25,7 @@ import ctypes -from serial.tools import list_ports_common +from serial_labgrid.tools import list_ports_common iokit = ctypes.cdll.LoadLibrary('/System/Library/Frameworks/IOKit.framework/IOKit') cf = ctypes.cdll.LoadLibrary('/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation') diff --git a/serial/tools/list_ports_posix.py b/serial_labgrid/tools/list_ports_posix.py similarity index 94% rename from serial/tools/list_ports_posix.py rename to serial_labgrid/tools/list_ports_posix.py index 79bc8ed1..8c97a4a1 100644 --- a/serial/tools/list_ports_posix.py +++ b/serial_labgrid/tools/list_ports_posix.py @@ -21,16 +21,16 @@ import glob import sys import os -from serial.tools import list_ports_common +from serial_labgrid.tools import list_ports_common # try to detect the OS so that a device can be selected... plat = sys.platform.lower() if plat[:5] == 'linux': # Linux (confirmed) # noqa - from serial.tools.list_ports_linux import comports + from serial_labgrid.tools.list_ports_linux import comports elif plat[:6] == 'darwin': # OS X (confirmed) - from serial.tools.list_ports_osx import comports + from serial_labgrid.tools.list_ports_osx import comports elif plat == 'cygwin': # cygwin/win32 # cygwin accepts /dev/com* in many contexts @@ -98,7 +98,7 @@ def comports(include_links=False): else: # platform detection has failed... - import serial + import serial_labgrid sys.stderr.write("""\ don't know how to enumerate ttys on this system. ! I you know how the serial ports are named send this information to @@ -110,7 +110,7 @@ def comports(include_links=False): also add the naming scheme of the serial ports and with a bit luck you can get this module running... -""".format(sys.platform, os.name, serial.VERSION)) +""".format(sys.platform, os.name, serial_labgrid.VERSION)) raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name)) # test diff --git a/serial/tools/list_ports_windows.py b/serial_labgrid/tools/list_ports_windows.py similarity index 99% rename from serial/tools/list_ports_windows.py rename to serial_labgrid/tools/list_ports_windows.py index 0b4a5b1e..7f689211 100644 --- a/serial/tools/list_ports_windows.py +++ b/serial_labgrid/tools/list_ports_windows.py @@ -21,9 +21,9 @@ from ctypes.wintypes import ULONG from ctypes.wintypes import HKEY from ctypes.wintypes import BYTE -import serial -from serial.win32 import ULONG_PTR -from serial.tools import list_ports_common +import serial_labgrid +from serial_labgrid.win32 import ULONG_PTR +from serial_labgrid.tools import list_ports_common def ValidHandle(value, func, arguments): diff --git a/serial/tools/miniterm.py b/serial_labgrid/tools/miniterm.py similarity index 96% rename from serial/tools/miniterm.py rename to serial_labgrid/tools/miniterm.py index 2cceff63..ca5e1e66 100644 --- a/serial/tools/miniterm.py +++ b/serial_labgrid/tools/miniterm.py @@ -14,9 +14,9 @@ import sys import threading -import serial -from serial.tools.list_ports import comports -from serial.tools import hexlify_codec +import serial_labgrid +from serial_labgrid.tools.list_ports import comports +from serial_labgrid.tools import hexlify_codec # pylint: disable=wrong-import-order,wrong-import-position @@ -480,7 +480,7 @@ def dump_port_settings(self): ('active' if self.serial.dsr else 'inactive'), ('active' if self.serial.ri else 'inactive'), ('active' if self.serial.cd else 'inactive'))) - except serial.SerialException: + except serial_labgrid.SerialException: # on RFC 2217 ports, it can happen if no modem state notification was # yet received. ignore this error. pass @@ -505,7 +505,7 @@ def reader(self): for transformation in self.rx_transformations: text = transformation.rx(text) self.console.write(text) - except serial.SerialException: + except serial_labgrid.SerialException: self.alive = False self.console.cancel() raise # XXX handle instead of re-raise? @@ -594,34 +594,34 @@ def handle_menu_key(self, c): elif c in 'bB': # B -> change baudrate self.change_baudrate() elif c == '8': # 8 -> change to 8 bits - self.serial.bytesize = serial.EIGHTBITS + self.serial.bytesize = serial_labgrid.EIGHTBITS self.dump_port_settings() elif c == '7': # 7 -> change to 8 bits - self.serial.bytesize = serial.SEVENBITS + self.serial.bytesize = serial_labgrid.SEVENBITS self.dump_port_settings() elif c in 'eE': # E -> change to even parity - self.serial.parity = serial.PARITY_EVEN + self.serial.parity = serial_labgrid.PARITY_EVEN self.dump_port_settings() elif c in 'oO': # O -> change to odd parity - self.serial.parity = serial.PARITY_ODD + self.serial.parity = serial_labgrid.PARITY_ODD self.dump_port_settings() elif c in 'mM': # M -> change to mark parity - self.serial.parity = serial.PARITY_MARK + self.serial.parity = serial_labgrid.PARITY_MARK self.dump_port_settings() elif c in 'sS': # S -> change to space parity - self.serial.parity = serial.PARITY_SPACE + self.serial.parity = serial_labgrid.PARITY_SPACE self.dump_port_settings() elif c in 'nN': # N -> change to no parity - self.serial.parity = serial.PARITY_NONE + self.serial.parity = serial_labgrid.PARITY_NONE self.dump_port_settings() elif c == '1': # 1 -> change to 1 stop bits - self.serial.stopbits = serial.STOPBITS_ONE + self.serial.stopbits = serial_labgrid.STOPBITS_ONE self.dump_port_settings() elif c == '2': # 2 -> change to 2 stop bits - self.serial.stopbits = serial.STOPBITS_TWO + self.serial.stopbits = serial_labgrid.STOPBITS_TWO self.dump_port_settings() elif c == '3': # 3 -> change to 1.5 stop bits - self.serial.stopbits = serial.STOPBITS_ONE_POINT_FIVE + self.serial.stopbits = serial_labgrid.STOPBITS_ONE_POINT_FIVE self.dump_port_settings() elif c in 'xX': # X -> change software flow control self.serial.xonxoff = (c == 'X') @@ -718,7 +718,7 @@ def change_port(self): # save settings settings = self.serial.getSettingsDict() try: - new_serial = serial.serial_for_url(port, do_not_open=True) + new_serial = serial_labgrid.serial_for_url(port, do_not_open=True) # restore settings and open new_serial.applySettingsDict(settings) new_serial.rts = self.serial.rts @@ -793,7 +793,7 @@ def get_help_text(self): --- b change baud rate --- x X disable/enable software flow control --- r R disable/enable hardware flow control -""".format(version=getattr(serial, 'VERSION', 'unknown version'), +""".format(version=getattr(serial_labgrid, 'VERSION', 'unknown version'), exit=key_description(self.exit_character), menu=key_description(self.menu_character), rts=key_description('\x12'), @@ -971,7 +971,7 @@ def main(default_port=None, default_baudrate=9600, default_rts=None, default_dtr if not args.port: parser.error('port is not given') try: - serial_instance = serial.serial_for_url( + serial_instance = serial_labgrid.serial_for_url( args.port, args.baudrate, parity=args.parity, @@ -992,11 +992,11 @@ def main(default_port=None, default_baudrate=9600, default_rts=None, default_dtr sys.stderr.write('--- forcing RTS {}\n'.format('active' if args.rts else 'inactive')) serial_instance.rts = args.rts - if isinstance(serial_instance, serial.Serial): + if isinstance(serial_instance, serial_labgrid.Serial): serial_instance.exclusive = args.exclusive serial_instance.open() - except serial.SerialException as e: + except serial_labgrid.SerialException as e: sys.stderr.write('could not open port {!r}: {}\n'.format(args.port, e)) if args.develop: raise diff --git a/serial/urlhandler/__init__.py b/serial_labgrid/urlhandler/__init__.py similarity index 100% rename from serial/urlhandler/__init__.py rename to serial_labgrid/urlhandler/__init__.py diff --git a/serial/urlhandler/protocol_alt.py b/serial_labgrid/urlhandler/protocol_alt.py similarity index 83% rename from serial/urlhandler/protocol_alt.py rename to serial_labgrid/urlhandler/protocol_alt.py index 2e666ca7..10067702 100644 --- a/serial/urlhandler/protocol_alt.py +++ b/serial_labgrid/urlhandler/protocol_alt.py @@ -23,14 +23,14 @@ except ImportError: import urllib.parse as urlparse -import serial +import serial_labgrid def serial_class_for_url(url): """extract host and port from an URL string""" parts = urlparse.urlsplit(url) if parts.scheme != 'alt': - raise serial.SerialException( + raise serial_labgrid.SerialException( 'expected a string in the form "alt://port[?option[=value][&option[=value]]]": ' 'not starting with alt:// ({!r})'.format(parts.scheme)) class_name = 'Serial' @@ -41,17 +41,17 @@ def serial_class_for_url(url): else: raise ValueError('unknown option: {!r}'.format(option)) except ValueError as e: - raise serial.SerialException( + raise serial_labgrid.SerialException( 'expected a string in the form ' '"alt://port[?option[=value][&option[=value]]]": {!r}'.format(e)) - if not hasattr(serial, class_name): + if not hasattr(serial_labgrid, class_name): raise ValueError('unknown class: {!r}'.format(class_name)) - cls = getattr(serial, class_name) - if not issubclass(cls, serial.Serial): + cls = getattr(serial_labgrid, class_name) + if not issubclass(cls, serial_labgrid.Serial): raise ValueError('class {!r} is not an instance of Serial'.format(class_name)) return (''.join([parts.netloc, parts.path]), cls) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if __name__ == '__main__': - s = serial.serial_for_url('alt:///dev/ttyS0?class=PosixPollSerial') + s = serial_labgrid.serial_for_url('alt:///dev/ttyS0?class=PosixPollSerial') print(s) diff --git a/serial/urlhandler/protocol_cp2110.py b/serial_labgrid/urlhandler/protocol_cp2110.py similarity index 93% rename from serial/urlhandler/protocol_cp2110.py rename to serial_labgrid/urlhandler/protocol_cp2110.py index 44ad4eb4..5e754bdb 100644 --- a/serial/urlhandler/protocol_cp2110.py +++ b/serial_labgrid/urlhandler/protocol_cp2110.py @@ -39,8 +39,8 @@ import hid # hidapi -import serial -from serial.serialutil import SerialBase, SerialException, PortNotOpenError, to_bytes, Timeout +import serial_labgrid +from serial_labgrid.serialutil import SerialBase, SerialException, PortNotOpenError, to_bytes, Timeout # Report IDs and related constant @@ -124,15 +124,15 @@ def close(self): def _reconfigure_port(self): parity_value = None - if self._parity == serial.PARITY_NONE: + if self._parity == serial_labgrid.PARITY_NONE: parity_value = 0x00 - elif self._parity == serial.PARITY_ODD: + elif self._parity == serial_labgrid.PARITY_ODD: parity_value = 0x01 - elif self._parity == serial.PARITY_EVEN: + elif self._parity == serial_labgrid.PARITY_EVEN: parity_value = 0x02 - elif self._parity == serial.PARITY_MARK: + elif self._parity == serial_labgrid.PARITY_MARK: parity_value = 0x03 - elif self._parity == serial.PARITY_SPACE: + elif self._parity == serial_labgrid.PARITY_SPACE: parity_value = 0x04 else: raise ValueError('Invalid parity: {!r}'.format(self._parity)) @@ -155,11 +155,11 @@ def _reconfigure_port(self): raise ValueError('Invalid char len: {!r}'.format(self._bytesize)) stop_bits_value = None - if self._stopbits == serial.STOPBITS_ONE: + if self._stopbits == serial_labgrid.STOPBITS_ONE: stop_bits_value = 0x00 - elif self._stopbits == serial.STOPBITS_ONE_POINT_FIVE: + elif self._stopbits == serial_labgrid.STOPBITS_ONE_POINT_FIVE: stop_bits_value = 0x01 - elif self._stopbits == serial.STOPBITS_TWO: + elif self._stopbits == serial_labgrid.STOPBITS_TWO: stop_bits_value = 0x01 else: raise ValueError('Invalid stop bit specification: {!r}'.format(self._stopbits)) diff --git a/serial/urlhandler/protocol_hwgrep.py b/serial_labgrid/urlhandler/protocol_hwgrep.py similarity index 82% rename from serial/urlhandler/protocol_hwgrep.py rename to serial_labgrid/urlhandler/protocol_hwgrep.py index 1a288c94..f426ed21 100644 --- a/serial/urlhandler/protocol_hwgrep.py +++ b/serial_labgrid/urlhandler/protocol_hwgrep.py @@ -22,8 +22,8 @@ from __future__ import absolute_import -import serial -import serial.tools.list_ports +import serial_labgrid +import serial_labgrid.tools.list_ports try: basestring @@ -31,17 +31,17 @@ basestring = str # python 3 pylint: disable=redefined-builtin -class Serial(serial.Serial): +class Serial(serial_labgrid.Serial): """Just inherit the native Serial port implementation and patch the port property.""" # pylint: disable=no-member - @serial.Serial.port.setter + @serial_labgrid.Serial.port.setter def port(self, value): """translate port name before storing it""" if isinstance(value, basestring) and value.startswith('hwgrep://'): - serial.Serial.port.__set__(self, self.from_url(value)) + serial_labgrid.Serial.port.__set__(self, self.from_url(value)) else: - serial.Serial.port.__set__(self, value) + serial_labgrid.Serial.port.__set__(self, value) def from_url(self, url): """extract host and port from an URL string""" @@ -68,11 +68,11 @@ def from_url(self, url): else: raise ValueError('unknown option: {!r}'.format(option)) # use a for loop to get the 1st element from the generator - for port, desc, hwid in sorted(serial.tools.list_ports.grep(regexp)): + for port, desc, hwid in sorted(serial_labgrid.tools.list_ports.grep(regexp)): if test_open: try: - s = serial.Serial(port) - except serial.SerialException: + s = serial_labgrid.Serial(port) + except serial_labgrid.SerialException: # it has some error, skip this one continue else: @@ -82,7 +82,7 @@ def from_url(self, url): continue return port else: - raise serial.SerialException('no ports found matching regexp {!r}'.format(url)) + raise serial_labgrid.SerialException('no ports found matching regexp {!r}'.format(url)) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if __name__ == '__main__': diff --git a/serial/urlhandler/protocol_loop.py b/serial_labgrid/urlhandler/protocol_loop.py similarity index 98% rename from serial/urlhandler/protocol_loop.py rename to serial_labgrid/urlhandler/protocol_loop.py index 2aeebfc7..fcd33762 100644 --- a/serial/urlhandler/protocol_loop.py +++ b/serial_labgrid/urlhandler/protocol_loop.py @@ -27,7 +27,7 @@ except ImportError: import Queue as queue -from serial.serialutil import SerialBase, SerialException, to_bytes, iterbytes, SerialTimeoutException, PortNotOpenError +from serial_labgrid.serialutil import SerialBase, SerialException, to_bytes, iterbytes, SerialTimeoutException, PortNotOpenError # map log level names to constants. used in from_url() LOGGER_LEVELS = { diff --git a/serial/urlhandler/protocol_rfc2217.py b/serial_labgrid/urlhandler/protocol_rfc2217.py similarity index 84% rename from serial/urlhandler/protocol_rfc2217.py rename to serial_labgrid/urlhandler/protocol_rfc2217.py index ebeec3a5..1f45244c 100644 --- a/serial/urlhandler/protocol_rfc2217.py +++ b/serial_labgrid/urlhandler/protocol_rfc2217.py @@ -9,4 +9,4 @@ from __future__ import absolute_import -from serial.rfc2217 import Serial # noqa +from serial_labgrid.rfc2217 import Serial # noqa diff --git a/serial/urlhandler/protocol_socket.py b/serial_labgrid/urlhandler/protocol_socket.py similarity index 99% rename from serial/urlhandler/protocol_socket.py rename to serial_labgrid/urlhandler/protocol_socket.py index 28884679..03043c1c 100644 --- a/serial/urlhandler/protocol_socket.py +++ b/serial_labgrid/urlhandler/protocol_socket.py @@ -28,7 +28,7 @@ except ImportError: import urllib.parse as urlparse -from serial.serialutil import SerialBase, SerialException, to_bytes, \ +from serial_labgrid.serialutil import SerialBase, SerialException, to_bytes, \ PortNotOpenError, SerialTimeoutException, Timeout # map log level names to constants. used in from_url() diff --git a/serial/urlhandler/protocol_spy.py b/serial_labgrid/urlhandler/protocol_spy.py similarity index 90% rename from serial/urlhandler/protocol_spy.py rename to serial_labgrid/urlhandler/protocol_spy.py index 67c700b9..e398e88b 100644 --- a/serial/urlhandler/protocol_spy.py +++ b/serial_labgrid/urlhandler/protocol_spy.py @@ -25,8 +25,8 @@ import sys import time -import serial -from serial.serialutil import to_bytes +import serial_labgrid +from serial_labgrid.serialutil import to_bytes try: import urlparse @@ -40,7 +40,7 @@ def sixteen(data): space after 8 bytes and (None, None) after 16 bytes and at the end. """ n = 0 - for b in serial.iterbytes(data): + for b in serial_labgrid.iterbytes(data): yield ('{:02X} '.format(ord(b)), b.decode('ascii') if b' ' <= b < b'\x7f' else '.') n += 1 if n == 8: @@ -152,7 +152,7 @@ def control(self, name, value): self.write_line(time.time() - self.start_time, name, value) -class Serial(serial.Serial): +class Serial(serial_labgrid.Serial): """\ Inherit the native Serial port implementation and wrap all the methods and attributes. @@ -164,16 +164,16 @@ def __init__(self, *args, **kwargs): self.formatter = None self.show_all = False - @serial.Serial.port.setter + @serial_labgrid.Serial.port.setter def port(self, value): if value is not None: - serial.Serial.port.__set__(self, self.from_url(value)) + serial_labgrid.Serial.port.__set__(self, self.from_url(value)) def from_url(self, url): """extract host and port from an URL string""" parts = urlparse.urlsplit(url) if parts.scheme != 'spy': - raise serial.SerialException( + raise serial_labgrid.SerialException( 'expected a string in the form ' '"spy://port[?option[=value][&option[=value]]]": ' 'not starting with spy:// ({!r})'.format(parts.scheme)) @@ -194,7 +194,7 @@ def from_url(self, url): else: raise ValueError('unknown option: {!r}'.format(option)) except ValueError as e: - raise serial.SerialException( + raise serial_labgrid.SerialException( 'expected a string in the form ' '"spy://port[?option[=value][&option[=value]]]": {}'.format(e)) self.formatter = formatter(output, color) @@ -211,12 +211,12 @@ def read(self, size=1): self.formatter.rx(rx) return rx - if hasattr(serial.Serial, 'cancel_read'): + if hasattr(serial_labgrid.Serial, 'cancel_read'): def cancel_read(self): self.formatter.control('Q-RX', 'cancel_read') super(Serial, self).cancel_read() - if hasattr(serial.Serial, 'cancel_write'): + if hasattr(serial_labgrid.Serial, 'cancel_write'): def cancel_write(self): self.formatter.control('Q-TX', 'cancel_write') super(Serial, self).cancel_write() @@ -244,40 +244,40 @@ def send_break(self, duration=0.25): self.formatter.control('BRK', 'send_break {}s'.format(duration)) super(Serial, self).send_break(duration) - @serial.Serial.break_condition.setter + @serial_labgrid.Serial.break_condition.setter def break_condition(self, level): self.formatter.control('BRK', 'active' if level else 'inactive') - serial.Serial.break_condition.__set__(self, level) + serial_labgrid.Serial.break_condition.__set__(self, level) - @serial.Serial.rts.setter + @serial_labgrid.Serial.rts.setter def rts(self, level): self.formatter.control('RTS', 'active' if level else 'inactive') - serial.Serial.rts.__set__(self, level) + serial_labgrid.Serial.rts.__set__(self, level) - @serial.Serial.dtr.setter + @serial_labgrid.Serial.dtr.setter def dtr(self, level): self.formatter.control('DTR', 'active' if level else 'inactive') - serial.Serial.dtr.__set__(self, level) + serial_labgrid.Serial.dtr.__set__(self, level) - @serial.Serial.cts.getter + @serial_labgrid.Serial.cts.getter def cts(self): level = super(Serial, self).cts self.formatter.control('CTS', 'active' if level else 'inactive') return level - @serial.Serial.dsr.getter + @serial_labgrid.Serial.dsr.getter def dsr(self): level = super(Serial, self).dsr self.formatter.control('DSR', 'active' if level else 'inactive') return level - @serial.Serial.ri.getter + @serial_labgrid.Serial.ri.getter def ri(self): level = super(Serial, self).ri self.formatter.control('RI', 'active' if level else 'inactive') return level - @serial.Serial.cd.getter + @serial_labgrid.Serial.cd.getter def cd(self): level = super(Serial, self).cd self.formatter.control('CD', 'active' if level else 'inactive') diff --git a/serial/win32.py b/serial_labgrid/win32.py similarity index 100% rename from serial/win32.py rename to serial_labgrid/win32.py diff --git a/test/handlers/protocol_test.py b/test/handlers/protocol_test.py index c0cffa6a..2287174f 100644 --- a/test/handlers/protocol_test.py +++ b/test/handlers/protocol_test.py @@ -10,7 +10,7 @@ # # URL format: test:// -from serial.serialutil import * +from serial_labgrid.serialutil import * import time import socket import logging diff --git a/test/run_all_tests.py b/test/run_all_tests.py index e0797e7e..7e092633 100644 --- a/test/run_all_tests.py +++ b/test/run_all_tests.py @@ -17,8 +17,8 @@ # inject local copy to avoid testing the installed version instead of the one in the repo sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -import serial # noqa -print("Patching sys.path to test local version. Testing Version: {}".format(serial.VERSION)) +import serial_labgrid # noqa +print("Patching sys.path to test local version. Testing Version: {}".format(serial_labgrid.VERSION)) PORT = 'loop://' if len(sys.argv) > 1: diff --git a/test/test.py b/test/test.py index db03907e..39271798 100644 --- a/test/test.py +++ b/test/test.py @@ -25,7 +25,7 @@ import threading import time import sys -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' @@ -44,7 +44,7 @@ class Test4_Nonblocking(unittest.TestCase): timeout = 0 def setUp(self): - self.s = serial.serial_for_url(PORT, timeout=self.timeout) + self.s = serial_labgrid.serial_for_url(PORT, timeout=self.timeout) def tearDown(self): self.s.close() @@ -119,7 +119,7 @@ class Test1_Forever(unittest.TestCase): character is sent after some time to stop the test, this is done through the SendEvent class and the Loopback HW.""" def setUp(self): - self.s = serial.serial_for_url(PORT, timeout=None) + self.s = serial_labgrid.serial_for_url(PORT, timeout=None) self.event = SendEvent(self.s) def tearDown(self): @@ -137,7 +137,7 @@ def test2_ReadEmpty(self): class Test2_Forever(unittest.TestCase): """Tests a port with no timeout""" def setUp(self): - self.s = serial.serial_for_url(PORT, timeout=None) + self.s = serial_labgrid.serial_for_url(PORT, timeout=None) def tearDown(self): self.s.close() @@ -162,7 +162,7 @@ def test2_Loopback(self): class Test0_DataWires(unittest.TestCase): """Test modem control lines""" def setUp(self): - self.s = serial.serial_for_url(PORT) + self.s = serial_labgrid.serial_for_url(PORT) def tearDown(self): self.s.close() @@ -194,7 +194,7 @@ class Test_MoreTimeouts(unittest.TestCase): """Test with timeouts""" def setUp(self): # create an closed serial port - self.s = serial.serial_for_url(PORT, do_not_open=True) + self.s = serial_labgrid.serial_for_url(PORT, do_not_open=True) def tearDown(self): self.s.reset_output_buffer() @@ -215,10 +215,10 @@ def test_WriteTimeout(self): self.s.write_timeout = 1.0 self.s.xonxoff = True self.s.open() - self.s.write(serial.XOFF) + self.s.write(serial_labgrid.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_labgrid.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 ({})".format(t2 - t1)) diff --git a/test/test_advanced.py b/test/test_advanced.py index 527cc479..23d5cb9d 100644 --- a/test/test_advanced.py +++ b/test/test_advanced.py @@ -20,7 +20,7 @@ """ import unittest -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' @@ -31,7 +31,7 @@ class Test_ChangeAttributes(unittest.TestCase): def setUp(self): # create a closed serial port - self.s = serial.serial_for_url(PORT, do_not_open=True) + self.s = serial_labgrid.serial_for_url(PORT, do_not_open=True) def tearDown(self): self.s.close() @@ -48,7 +48,7 @@ def test_PortSetting(self): def test_DoubleOpen(self): self.s.open() # calling open for a second time is an error - self.assertRaises(serial.SerialException, self.s.open) + self.assertRaises(serial_labgrid.SerialException, self.s.open) def test_BaudrateSetting(self): self.s.open() @@ -82,7 +82,7 @@ def test_BytesizeSetting(self): self.assertRaises(ValueError, setattr, self.s, 'bytesize', illegal_value) def test_ParitySetting(self): - for parity in (serial.PARITY_NONE, serial.PARITY_EVEN, serial.PARITY_ODD): + for parity in (serial_labgrid.PARITY_NONE, serial_labgrid.PARITY_EVEN, serial_labgrid.PARITY_ODD): self.s.parity = parity # test get method self.assertEqual(self.s.parity, parity) @@ -138,7 +138,7 @@ def test_RtsCtsSetting(self): # now, already sets a port def disabled_test_UnconfiguredPort(self): # an unconfigured port cannot be opened - self.assertRaises(serial.SerialException, self.s.open) + self.assertRaises(serial_labgrid.SerialException, self.s.open) def test_PortOpenClose(self): for i in range(3): diff --git a/test/test_asyncio.py b/test/test_asyncio.py index 5df8ef2f..ac6ea636 100644 --- a/test/test_asyncio.py +++ b/test/test_asyncio.py @@ -10,14 +10,14 @@ import os import unittest -import serial +import serial_labgrid # on which port should the tests be performed: PORT = '/dev/ttyUSB0' try: import asyncio - import serial.aio + import serial_labgrid.aio except (ImportError, SyntaxError): # not compatible with python 2.x pass @@ -64,7 +64,7 @@ def resume_writing(self): actions.append('resume') print(self.transport.get_write_buffer_size()) - coro = serial.aio.create_serial_connection(self.loop, Output, PORT, baudrate=115200) + coro = serial_labgrid.aio.create_serial_connection(self.loop, Output, PORT, baudrate=115200) self.loop.run_until_complete(coro) self.loop.run_forever() self.assertEqual(b''.join(received), TEXT) diff --git a/test/test_cancel.py b/test/test_cancel.py index daab1cec..d2b5f7c1 100644 --- a/test/test_cancel.py +++ b/test/test_cancel.py @@ -11,19 +11,19 @@ import unittest import threading import time -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' -@unittest.skipIf(not hasattr(serial.Serial, 'cancel_read'), "cancel_read not supported on platform") +@unittest.skipIf(not hasattr(serial_labgrid.Serial, 'cancel_read'), "cancel_read not supported on platform") class TestCancelRead(unittest.TestCase): """Test cancel_read functionality""" def setUp(self): # create a closed serial port - self.s = serial.serial_for_url(PORT) + self.s = serial_labgrid.serial_for_url(PORT) self.assertTrue(hasattr(self.s, 'cancel_read'), "serial instance has no cancel_read") self.s.timeout = 10 self.cancel_called = 0 @@ -57,13 +57,13 @@ def test_cancel_once(self): DATA = b'#' * 1024 -@unittest.skipIf(not hasattr(serial.Serial, 'cancel_write'), "cancel_read not supported on platform") +@unittest.skipIf(not hasattr(serial_labgrid.Serial, 'cancel_write'), "cancel_read not supported on platform") class TestCancelWrite(unittest.TestCase): """Test cancel_write functionality""" def setUp(self): # create a closed serial port - self.s = serial.serial_for_url(PORT, baudrate=300) # extra slow ~30B/s => 1kb ~ 34s + self.s = serial_labgrid.serial_for_url(PORT, baudrate=300) # extra slow ~30B/s => 1kb ~ 34s self.assertTrue(hasattr(self.s, 'cancel_write'), "serial instance has no cancel_write") self.s.write_timeout = 10 self.cancel_called = 0 diff --git a/test/test_context.py b/test/test_context.py index 456c85a5..a1ffe63f 100755 --- a/test/test_context.py +++ b/test/test_context.py @@ -15,7 +15,7 @@ """ import unittest -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' @@ -26,7 +26,7 @@ class Test_Context(unittest.TestCase): def setUp(self): # create a closed serial port - self.s = serial.serial_for_url(PORT) + self.s = serial_labgrid.serial_for_url(PORT) def tearDown(self): self.s.close() diff --git a/test/test_exclusive.py b/test/test_exclusive.py index f66db14f..e5bc8374 100644 --- a/test/test_exclusive.py +++ b/test/test_exclusive.py @@ -11,7 +11,7 @@ import os import unittest import sys -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' @@ -20,33 +20,33 @@ class Test_exclusive(unittest.TestCase): """Test serial port locking""" def setUp(self): - with serial.serial_for_url(PORT, do_not_open=True) as x: - if not isinstance(x, serial.Serial): + with serial_labgrid.serial_for_url(PORT, do_not_open=True) as x: + if not isinstance(x, serial_labgrid.Serial): raise unittest.SkipTest("exclusive test only compatible with real serial port") def test_exclusive_none(self): """test for exclusive=None""" - with serial.Serial(PORT, exclusive=None): + with serial_labgrid.Serial(PORT, exclusive=None): pass # OK @unittest.skipUnless(os.name == 'posix', "exclusive=False not supported on platform") def test_exclusive_false(self): """test for exclusive=False""" - with serial.Serial(PORT, exclusive=False): + with serial_labgrid.Serial(PORT, exclusive=False): pass # OK @unittest.skipUnless(os.name in ('posix', 'nt'), "exclusive=True setting not supported on platform") def test_exclusive_true(self): """test for exclusive=True""" - with serial.Serial(PORT, exclusive=True): - with self.assertRaises(serial.SerialException): - serial.Serial(PORT, exclusive=True) # fails to open twice + with serial_labgrid.Serial(PORT, exclusive=True): + with self.assertRaises(serial_labgrid.SerialException): + serial_labgrid.Serial(PORT, exclusive=True) # fails to open twice @unittest.skipUnless(os.name == 'nt', "platform is not restricted to exclusive=True (and None)") def test_exclusive_only_true(self): """test if exclusive=False is not supported""" with self.assertRaises(ValueError): - serial.Serial(PORT, exclusive=False) # expected to fail: False not supported + serial_labgrid.Serial(PORT, exclusive=False) # expected to fail: False not supported if __name__ == '__main__': diff --git a/test/test_high_load.py b/test/test_high_load.py index b0bd7739..977a75f3 100644 --- a/test/test_high_load.py +++ b/test/test_high_load.py @@ -22,7 +22,7 @@ import unittest import sys -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' @@ -42,7 +42,7 @@ class TestHighLoad(unittest.TestCase): #~ N = 1 def setUp(self): - self.s = serial.serial_for_url(PORT, BAUDRATE, timeout=10) + self.s = serial_labgrid.serial_for_url(PORT, BAUDRATE, timeout=10) def tearDown(self): self.s.close() diff --git a/test/test_iolib.py b/test/test_iolib.py index 84e3fa24..919a8fa9 100644 --- a/test/test_iolib.py +++ b/test/test_iolib.py @@ -27,7 +27,7 @@ import io import sys import unittest -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' @@ -36,7 +36,7 @@ class Test_SerialAndIO(unittest.TestCase): def setUp(self): - self.s = serial.serial_for_url(PORT, timeout=1) + self.s = serial_labgrid.serial_for_url(PORT, timeout=1) #~ self.io = io.TextIOWrapper(self.s) self.io = io.TextIOWrapper(io.BufferedRWPair(self.s, self.s)) diff --git a/test/test_pty.py b/test/test_pty.py index 6606ff7b..7a3bd938 100644 --- a/test/test_pty.py +++ b/test/test_pty.py @@ -16,7 +16,7 @@ except ImportError: pty = None import unittest -import serial +import serial_labgrid DATA = b'Hello\n' @@ -29,11 +29,11 @@ def setUp(self): self.master, self.slave = pty.openpty() def test_pty_serial_open_slave(self): - with serial.Serial(os.ttyname(self.slave), timeout=1) as slave: + with serial_labgrid.Serial(os.ttyname(self.slave), timeout=1) as slave: pass # OK def test_pty_serial_write(self): - with serial.Serial(os.ttyname(self.slave), timeout=1) as slave: + with serial_labgrid.Serial(os.ttyname(self.slave), timeout=1) as slave: with os.fdopen(self.master, "wb") as fd: fd.write(DATA) fd.flush() @@ -41,7 +41,7 @@ def test_pty_serial_write(self): self.assertEqual(DATA, out) def test_pty_serial_read(self): - with serial.Serial(os.ttyname(self.slave), timeout=1) as slave: + with serial_labgrid.Serial(os.ttyname(self.slave), timeout=1) as slave: with os.fdopen(self.master, "rb") as fd: slave.write(DATA) slave.flush() diff --git a/test/test_readline.py b/test/test_readline.py index 34b807b2..d69e499d 100644 --- a/test/test_readline.py +++ b/test/test_readline.py @@ -23,7 +23,7 @@ import unittest import sys -import serial +import serial_labgrid #~ print serial.VERSION @@ -42,55 +42,55 @@ class Test_Readline(unittest.TestCase): """Test readline function""" def setUp(self): - self.s = serial.serial_for_url(PORT, timeout=1) + self.s = serial_labgrid.serial_for_url(PORT, timeout=1) def tearDown(self): self.s.close() def test_readline(self): """Test readline method""" - self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) - self.assertEqual(self.s.readline(), serial.to_bytes([0x31, 0x0a])) - self.assertEqual(self.s.readline(), serial.to_bytes([0x32, 0x0a])) - self.assertEqual(self.s.readline(), serial.to_bytes([0x33, 0x0a])) + self.s.write(serial_labgrid.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) + self.assertEqual(self.s.readline(), serial_labgrid.to_bytes([0x31, 0x0a])) + self.assertEqual(self.s.readline(), serial_labgrid.to_bytes([0x32, 0x0a])) + self.assertEqual(self.s.readline(), serial_labgrid.to_bytes([0x33, 0x0a])) # this time we will get a timeout - self.assertEqual(self.s.readline(), serial.to_bytes([])) + self.assertEqual(self.s.readline(), serial_labgrid.to_bytes([])) def test_readlines(self): """Test readlines method""" - self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) + self.s.write(serial_labgrid.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) self.assertEqual( self.s.readlines(), - [serial.to_bytes([0x31, 0x0a]), serial.to_bytes([0x32, 0x0a]), serial.to_bytes([0x33, 0x0a])] + [serial_labgrid.to_bytes([0x31, 0x0a]), serial_labgrid.to_bytes([0x32, 0x0a]), serial_labgrid.to_bytes([0x33, 0x0a])] ) def test_xreadlines(self): """Test xreadlines method (skipped for io based systems)""" if hasattr(self.s, 'xreadlines'): - self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) + self.s.write(serial_labgrid.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) self.assertEqual( list(self.s.xreadlines()), - [serial.to_bytes([0x31, 0x0a]), serial.to_bytes([0x32, 0x0a]), serial.to_bytes([0x33, 0x0a])] + [serial_labgrid.to_bytes([0x31, 0x0a]), serial_labgrid.to_bytes([0x32, 0x0a]), serial_labgrid.to_bytes([0x33, 0x0a])] ) def test_for_in(self): """Test for line in s""" - self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) + self.s.write(serial_labgrid.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) lines = [] for line in self.s: lines.append(line) self.assertEqual( lines, - [serial.to_bytes([0x31, 0x0a]), serial.to_bytes([0x32, 0x0a]), serial.to_bytes([0x33, 0x0a])] + [serial_labgrid.to_bytes([0x31, 0x0a]), serial_labgrid.to_bytes([0x32, 0x0a]), serial_labgrid.to_bytes([0x33, 0x0a])] ) 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 - self.s.write(serial.to_bytes("no\rno\nyes\r\n")) + self.s.write(serial_labgrid.to_bytes("no\rno\nyes\r\n")) self.assertEqual( - self.s.readline(eol=serial.to_bytes("\r\n")), - serial.to_bytes("no\rno\nyes\r\n")) + self.s.readline(eol=serial_labgrid.to_bytes("\r\n")), + serial_labgrid.to_bytes("no\rno\nyes\r\n")) if __name__ == '__main__': diff --git a/test/test_rfc2217.py b/test/test_rfc2217.py index 7dbe2a68..13a5be7f 100644 --- a/test/test_rfc2217.py +++ b/test/test_rfc2217.py @@ -9,8 +9,8 @@ """ import unittest -import serial -import serial.rfc2217 +import serial_labgrid +import serial_labgrid.rfc2217 class Test_RFC2217(unittest.TestCase): @@ -18,17 +18,17 @@ class Test_RFC2217(unittest.TestCase): def test_failed_connection(self): # connection to closed port - s = serial.serial_for_url('rfc2217://127.99.99.99:2217', do_not_open=True) - self.assertRaises(serial.SerialException, s.open) + s = serial_labgrid.serial_for_url('rfc2217://127.99.99.99:2217', do_not_open=True) + self.assertRaises(serial_labgrid.SerialException, s.open) self.assertFalse(s.is_open) s.close() # no errors expected # invalid address - s = serial.serial_for_url('rfc2217://127goingtofail', do_not_open=True) - self.assertRaises(serial.SerialException, s.open) + s = serial_labgrid.serial_for_url('rfc2217://127goingtofail', do_not_open=True) + self.assertRaises(serial_labgrid.SerialException, s.open) self.assertFalse(s.is_open) s.close() # no errors expected # close w/o open is also OK - s = serial.serial_for_url('rfc2217://irrelevant', do_not_open=True) + s = serial_labgrid.serial_for_url('rfc2217://irrelevant', do_not_open=True) self.assertFalse(s.is_open) s.close() # no errors expected diff --git a/test/test_rs485.py b/test/test_rs485.py index e918f67d..b304ab0f 100644 --- a/test/test_rs485.py +++ b/test/test_rs485.py @@ -9,8 +9,8 @@ """ import unittest -import serial -import serial.rs485 +import serial_labgrid +import serial_labgrid.rs485 # on which port should the tests be performed: PORT = 'loop://' @@ -21,7 +21,7 @@ class Test_RS485_settings(unittest.TestCase): def setUp(self): # create a closed serial port - self.s = serial.serial_for_url(PORT, do_not_open=True) + self.s = serial_labgrid.serial_for_url(PORT, do_not_open=True) def tearDown(self): self.s.close() @@ -31,7 +31,7 @@ def test_enable_RS485(self): #~ self.s.open() self.assertEqual(self.s._rs485_mode, None, 'RS485 is disabled by default') self.assertEqual(self.s.rs485_mode, None, 'RS485 is disabled by default') - self.s.rs485_mode = serial.rs485.RS485Settings() + self.s.rs485_mode = serial_labgrid.rs485.RS485Settings() self.assertTrue(self.s._rs485_mode is not None, 'RS485 is enabled') self.assertTrue(self.s.rs485_mode is not None, 'RS485 is enabled') self.s.rs485_mode = None @@ -43,15 +43,15 @@ class Test_RS485_class(unittest.TestCase): """Test RS485 class""" def setUp(self): - if not isinstance(serial.serial_for_url(PORT), serial.Serial): + if not isinstance(serial_labgrid.serial_for_url(PORT), serial_labgrid.Serial): raise unittest.SkipTest("RS485 test only compatible with real serial port") - self.s = serial.rs485.RS485(PORT, timeout=1) + self.s = serial_labgrid.rs485.RS485(PORT, timeout=1) def tearDown(self): self.s.close() def test_RS485_class(self): - self.s.rs485_mode = serial.rs485.RS485Settings() + self.s.rs485_mode = serial_labgrid.rs485.RS485Settings() self.s.write(b'hello') self.assertEqual(self.s.read(5), b'hello') diff --git a/test/test_settings_dict.py b/test/test_settings_dict.py index 86ee4b21..977dd6ce 100644 --- a/test/test_settings_dict.py +++ b/test/test_settings_dict.py @@ -12,7 +12,7 @@ """ import unittest -import serial +import serial_labgrid # on which port should the tests be performed: PORT = 'loop://' @@ -27,14 +27,14 @@ class Test_SettingsDict(unittest.TestCase): def test_getsettings(self): """the settings dict reflects the current settings""" - ser = serial.serial_for_url(PORT, do_not_open=True) + ser = serial_labgrid.serial_for_url(PORT, do_not_open=True) d = ser.get_settings() for setting in SETTINGS: self.assertEqual(getattr(ser, setting), d[setting]) def test_partial_settings(self): """partial settings dictionaries are also accepted""" - ser = serial.serial_for_url(PORT, do_not_open=True) + ser = serial_labgrid.serial_for_url(PORT, do_not_open=True) d = ser.get_settings() del d['baudrate'] del d['bytesize'] @@ -44,7 +44,7 @@ def test_partial_settings(self): def test_unknown_settings(self): """unknown settings are ignored""" - ser = serial.serial_for_url(PORT, do_not_open=True) + ser = serial_labgrid.serial_for_url(PORT, do_not_open=True) d = ser.get_settings() d['foobar'] = 'ignore me' ser.apply_settings(d) @@ -56,14 +56,14 @@ def test_init_sets_the_correct_attrs(self): ('timeout', 7), ('write_timeout', 12), ('inter_byte_timeout', 15), - ('stopbits', serial.STOPBITS_TWO), - ('bytesize', serial.SEVENBITS), - ('parity', serial.PARITY_ODD), + ('stopbits', serial_labgrid.STOPBITS_TWO), + ('bytesize', serial_labgrid.SEVENBITS), + ('parity', serial_labgrid.PARITY_ODD), ('xonxoff', True), ('rtscts', True), ('dsrdtr', True)): kwargs = {'do_not_open': True, setting: value} - ser = serial.serial_for_url(PORT, **kwargs) + ser = serial_labgrid.serial_for_url(PORT, **kwargs) d = ser.get_settings() self.assertEqual(getattr(ser, setting), value) self.assertEqual(d[setting], value) diff --git a/test/test_threaded.py b/test/test_threaded.py index 40f45ad7..4a1ce970 100644 --- a/test/test_threaded.py +++ b/test/test_threaded.py @@ -10,8 +10,8 @@ import os import unittest -import serial -import serial.threaded +import serial_labgrid +import serial_labgrid.threaded import time @@ -24,7 +24,7 @@ class Test_threaded(unittest.TestCase): def test_line_reader(self): """simple test of line reader class""" - class TestLines(serial.threaded.LineReader): + class TestLines(serial_labgrid.threaded.LineReader): def __init__(self): super(TestLines, self).__init__() self.received_lines = [] @@ -32,8 +32,8 @@ def __init__(self): def handle_line(self, data): self.received_lines.append(data) - ser = serial.serial_for_url(PORT, baudrate=115200, timeout=1) - with serial.threaded.ReaderThread(ser, TestLines) as protocol: + ser = serial_labgrid.serial_for_url(PORT, baudrate=115200, timeout=1) + with serial_labgrid.threaded.ReaderThread(ser, TestLines) as protocol: protocol.write_line('hello') protocol.write_line('world') time.sleep(1) @@ -42,7 +42,7 @@ def handle_line(self, data): def test_framed_packet(self): """simple test of line reader class""" - class TestFramedPacket(serial.threaded.FramedPacket): + class TestFramedPacket(serial_labgrid.threaded.FramedPacket): def __init__(self): super(TestFramedPacket, self).__init__() self.received_packets = [] @@ -55,8 +55,8 @@ def send_packet(self, packet): self.transport.write(packet) self.transport.write(self.STOP) - ser = serial.serial_for_url(PORT, baudrate=115200, timeout=1) - with serial.threaded.ReaderThread(ser, TestFramedPacket) as protocol: + ser = serial_labgrid.serial_for_url(PORT, baudrate=115200, timeout=1) + with serial_labgrid.threaded.ReaderThread(ser, TestFramedPacket) as protocol: protocol.send_packet(b'1') protocol.send_packet(b'2') protocol.send_packet(b'3') diff --git a/test/test_timeout_class.py b/test/test_timeout_class.py index 37c38b1e..709ddb24 100644 --- a/test/test_timeout_class.py +++ b/test/test_timeout_class.py @@ -10,7 +10,7 @@ import sys import unittest import time -from serial import serialutil +from serial_labgrid import serialutil class TestTimeoutClass(unittest.TestCase): diff --git a/test/test_url.py b/test/test_url.py index e37d3fa9..91c08cef 100644 --- a/test/test_url.py +++ b/test/test_url.py @@ -15,7 +15,7 @@ """ import unittest -import serial +import serial_labgrid class Test_URL(unittest.TestCase): @@ -23,24 +23,24 @@ class Test_URL(unittest.TestCase): def test_loop(self): """loop interface""" - serial.serial_for_url('loop://', do_not_open=True) + serial_labgrid.serial_for_url('loop://', do_not_open=True) def test_bad_url(self): """invalid protocol specified""" - self.assertRaises(ValueError, serial.serial_for_url, "imnotknown://") + self.assertRaises(ValueError, serial_labgrid.serial_for_url, "imnotknown://") def test_custom_url(self): """custom protocol handlers""" # it's unknown - self.assertRaises(ValueError, serial.serial_for_url, "test://") + self.assertRaises(ValueError, serial_labgrid.serial_for_url, "test://") # add search path - serial.protocol_handler_packages.append('handlers') + serial_labgrid.protocol_handler_packages.append('handlers') # now it should work - serial.serial_for_url("test://") + serial_labgrid.serial_for_url("test://") # remove our handler again - serial.protocol_handler_packages.remove('handlers') + serial_labgrid.protocol_handler_packages.remove('handlers') # so it should not work anymore - self.assertRaises(ValueError, serial.serial_for_url, "test://") + self.assertRaises(ValueError, serial_labgrid.serial_for_url, "test://") if __name__ == '__main__': diff --git a/test/test_util.py b/test/test_util.py index 5bf8e606..8cac044f 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -10,22 +10,22 @@ import os import unittest -import serial +import serial_labgrid class Test_util(unittest.TestCase): """Test serial utility functions""" def test_to_bytes(self): - self.assertEqual(serial.to_bytes([1, 2, 3]), b'\x01\x02\x03') - self.assertEqual(serial.to_bytes(b'\x01\x02\x03'), b'\x01\x02\x03') - self.assertEqual(serial.to_bytes(bytearray([1,2,3])), b'\x01\x02\x03') + self.assertEqual(serial_labgrid.to_bytes([1, 2, 3]), b'\x01\x02\x03') + self.assertEqual(serial_labgrid.to_bytes(b'\x01\x02\x03'), b'\x01\x02\x03') + self.assertEqual(serial_labgrid.to_bytes(bytearray([1,2,3])), b'\x01\x02\x03') # unicode is not supported test. use decode() instead of u'' syntax to be # compatible to Python 3.x < 3.4 - self.assertRaises(TypeError, serial.to_bytes, b'hello'.decode('utf-8')) + self.assertRaises(TypeError, serial_labgrid.to_bytes, b'hello'.decode('utf-8')) def test_iterbytes(self): - self.assertEqual(list(serial.iterbytes(b'\x01\x02\x03')), [b'\x01', b'\x02', b'\x03']) + self.assertEqual(list(serial_labgrid.iterbytes(b'\x01\x02\x03')), [b'\x01', b'\x02', b'\x03']) if __name__ == '__main__':