Documentation for dummy_serial (which is a serial port mock)

dummy_serial: A dummy/mock implementation of a serial port for testing purposes.

This Python file was changed (committed) at $Date: 2012-08-26 16:14:30 +0200 (Sun, 26 Aug 2012) $, which was $Revision: 155 $.

dummy_serial.VERBOSE = False

Set this to True for printing the communication, and also details on the port initialization.

dummy_serial.RESPONSES = {'EXAMPLEMESSAGE': 'EXAMPLERESPONSE'}

A dictionary of respones from the dummy serial port.

The key is the message (string) sent to the dummy serial port, and the item is the response (string) from the dummy serial port.

Intended to be monkey-patched in the calling test module.

dummy_serial.DEFAULT_RESPONSE = ''

Response when no matching message (key) is found in the look-up dictionary.

Might be monkey-patched in the calling test module.

class dummy_serial.Serial(*args, **kwargs)[source]

Dummy (mock) serial port for testing purposes.

Mimics the behavior of a serial port as defined by the pySerial module.

Args:
(whatever): The arguments are not used.

Note: As the portname argument not is used, only one port on dummy_serial can be used simultaneously.

open()[source]

Open a (previously initialized) port on dummy_serial.

close()[source]

Close a port on dummy_serial.

write(inputdata)[source]

Write to a port on dummy_serial.

Args:
inputdata (string/bytes): data for sending to the port on dummy_serial. Will affect the response.

Note that for Python2, the inputdata should be a string. For Python3 it should be of type bytes.

read(numberOfBytes)[source]

Read from a port on dummy_serial.

The response is dependent on what was written last to the port on dummy_serial, and what is defined in the RESPONSES dictionary.

Args:
numberOfBytes (int): For compability with the real function. Not used.

Returns a string for Python2 and bytes for Python3.

Previous topic

Internal documentation for unit testing of MinimalModbus

Next topic

Internal documentation for unit testing of eurotherm3500

This Page

Get minimalmodbus at SourceForge.net. Fast, secure and Free Open Source software downloads