Internal documentation for unit testing of MinimalModbus

test_minimalmodbus: Unittests for the minimalmodbus module.

For each function are these tests performed:

  • Known results
  • Invalid input value
  • Invalid input type

This unittest suite uses a mock/dummy serial port from the module dummy_serial, so it is possible to test the functionality using previously recorded communication data.

With dummy responses, it is also possible to simulate errors in the communication from the slave. A few different types of communication errors are tested, as seen in this table.

Simulated response error Tested using function Tested using Modbus function code
No response read_bit 2
Wrong CRC in response write_register 16
Wrong slave address in response write_register 16
Wrong function code in response write_register 16
Slave indicates an error write_register 16
Wrong byte count in response read_bit 2
Wrong register address in response write_register 16
Wrong number of registers in response write_bit 15
Wrong number of registers in response write_register 16
Wrong write data in response write_bit 5
Wrong write data in response write_register 6
test_minimalmodbus.ALSO_TIME_CONSUMING_TESTS = True

Set this to False to skip the most time consuming tests

test_minimalmodbus.VERBOSITY = 0

Verbosity level for the unit testing. Use value 0 or 2. Note that it only has an effect for Python 2.7 and above.

test_minimalmodbus.SHOW_ERROR_MESSAGES_FOR_ASSERTRAISES = False

Set this to True for printing the error messages caught by assertRaises().

If set to True, any unintentional error messages raised during the processing of the command in assertRaises() are also caught (not counted). It will be printed in the short form, and will show no traceback. It can also be useful to set VERBOSITY = 2.

exception test_minimalmodbus._NonexistantError[source]
class test_minimalmodbus.ExtendedTestCase(methodName='runTest')[source]

Overriding the assertRaises() method to be able to print the error message.

Use test_minimalmodbus.SHOW_ERROR_MESSAGES_FOR_ASSERTRAISES = True in order to use this option. It can also be useful to set test_minimalmodbus.VERBOSITY = 2.

Based on http://stackoverflow.com/questions/8672754/how-to-show-the-error-messages-caught-by-assertraises-in-unittest-in-python2-7

assertRaises(excClass, callableObj, *args, **kwargs)[source]

Prints the caught error message (if SHOW_ERROR_MESSAGES_FOR_ASSERTRAISES is True).

assertAlmostEqualRatio(first, second, epsilon=1.000001)[source]

A function to compare floats, with ratio instead of difference.

Args:
  • first (float): Input argument for comparison
  • second (float): Input argument for comparison
  • epsilon (float): Largest allowed ratio of largest to smallest of the two input arguments
class test_minimalmodbus.TestEmbedPayload(methodName='runTest')[source]
knownValues = [(2, 2, 'rtu', '123', '\x02\x02123X\xc2'), (1, 16, 'rtu', 'ABC', '\x01\x10ABC<E'), (0, 5, 'rtu', 'hjl', '\x00\x05hjl\x8b\x9d'), (1, 3, 'rtu', '\x01\x02\x03', '\x01\x03\x01\x02\x03\t%'), (1, 3, 'ascii', '123', ':010331323366\r\n'), (4, 5, 'ascii', '\x01\x02\x03', ':0405010203F1\r\n'), (2, 2, 'ascii', '123', ':020231323366\r\n')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestExtractPayload(methodName='runTest')[source]
knownValues = [(2, 2, 'rtu', '123', '\x02\x02123X\xc2'), (1, 16, 'rtu', 'ABC', '\x01\x10ABC<E'), (0, 5, 'rtu', 'hjl', '\x00\x05hjl\x8b\x9d'), (1, 3, 'rtu', '\x01\x02\x03', '\x01\x03\x01\x02\x03\t%'), (1, 3, 'ascii', '123', ':010331323366\r\n'), (4, 5, 'ascii', '\x01\x02\x03', ':0405010203F1\r\n'), (2, 2, 'ascii', '123', ':020231323366\r\n')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityEmbedExtractPayload(methodName='runTest')[source]
knownValues = [(2, 2, 'rtu', '123', '\x02\x02123X\xc2'), (1, 16, 'rtu', 'ABC', '\x01\x10ABC<E'), (0, 5, 'rtu', 'hjl', '\x00\x05hjl\x8b\x9d'), (1, 3, 'rtu', '\x01\x02\x03', '\x01\x03\x01\x02\x03\t%'), (1, 3, 'ascii', '123', ':010331323366\r\n'), (4, 5, 'ascii', '\x01\x02\x03', ':0405010203F1\r\n'), (2, 2, 'ascii', '123', ':020231323366\r\n')]
testKnownValues()[source]
testRange()[source]
class test_minimalmodbus.TestPredictResponseSize(methodName='runTest')[source]
knownValues = [('rtu', 1, '\x00>\x00\x01', 6), ('rtu', 1, '\x00>\x00\x07', 6), ('rtu', 1, '\x00>\x00\x08', 6), ('rtu', 1, '\x00>\x00\t', 7), ('rtu', 3, 'AB\x00\x07', 19), ('rtu', 4, 'AB\x00\x07', 19), ('rtu', 4, 'AB\x01\x07', 531), ('rtu', 5, '\x00G\xff\x00', 8), ('rtu', 16, '\x00H\x00\x01\x01\x01', 8), ('ascii', 1, '\x00>\x00\x01', 13), ('ascii', 1, '\x00>\x00\x07', 13), ('ascii', 1, '\x00>\x00\x08', 13), ('ascii', 1, '\x00>\x00\t', 15), ('ascii', 3, 'AB\x00\x07', 39), ('ascii', 4, 'AB\x00\x07', 39), ('ascii', 4, 'AB\x01\x07', 1063), ('ascii', 5, '\x00G\xff\x00', 17), ('ascii', 16, '\x00H\x00\x01\x01\x01', 17)]
testKnownValues()[source]
testRecordedRtuMessages()[source]
testRecordedAsciiMessages()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestCalculateMinimumSilentPeriod(methodName='runTest')[source]
knownValues = [(2400, 0.016), (2400.0, 0.016), (4800, 0.008), (9600, 0.004), (19200, 0.002), (38400, 0.001), (115200, 0.00033)]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestNumToOneByteString(methodName='runTest')[source]
knownValues = [(0, '\x00'), (7, '\x07'), (255, '\xff')]
testKnownValues()[source]
testKnownLoop()[source]
testWrongInput()[source]
testWrongType()[source]
class test_minimalmodbus.TestNumToTwoByteString(methodName='runTest')[source]
knownValues = [(0.0, 0, False, False, '\x00\x00'), (0, 0, False, False, '\x00\x00'), (0, 0, True, False, '\x00\x00'), (77.0, 1, False, False, '\x03\x02'), (77.0, 1, True, False, '\x02\x03'), (770, 0, False, False, '\x03\x02'), (770, 0, True, False, '\x02\x03'), (65535, 0, False, False, '\xff\xff'), (65535, 0, True, False, '\xff\xff'), (770, 0, False, True, '\x03\x02'), (77.0, 1, False, True, '\x03\x02'), (0.0, 0, False, True, '\x00\x00'), (0.0, 3, False, True, '\x00\x00'), (-1, 0, False, True, '\xff\xff'), (-1, 1, False, True, '\xff\xf6'), (-77, 0, False, True, '\xff\xb3'), (-770, 0, False, True, '\xfc\xfe'), (-77, 1, False, True, '\xfc\xfe'), (-32768, 0, False, True, '\x80\x00'), (32767, 0, False, True, '\x7f\xff')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestTwoByteStringToNum(methodName='runTest')[source]
knownValues = [(0.0, 0, False, False, '\x00\x00'), (0, 0, False, False, '\x00\x00'), (0, 0, True, False, '\x00\x00'), (77.0, 1, False, False, '\x03\x02'), (77.0, 1, True, False, '\x02\x03'), (770, 0, False, False, '\x03\x02'), (770, 0, True, False, '\x02\x03'), (65535, 0, False, False, '\xff\xff'), (65535, 0, True, False, '\xff\xff'), (770, 0, False, True, '\x03\x02'), (77.0, 1, False, True, '\x03\x02'), (0.0, 0, False, True, '\x00\x00'), (0.0, 3, False, True, '\x00\x00'), (-1, 0, False, True, '\xff\xff'), (-1, 1, False, True, '\xff\xf6'), (-77, 0, False, True, '\xff\xb3'), (-770, 0, False, True, '\xfc\xfe'), (-77, 1, False, True, '\xfc\xfe'), (-32768, 0, False, True, '\x80\x00'), (32767, 0, False, True, '\x7f\xff')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityTwoByteString(methodName='runTest')[source]
knownValues = [(0.0, 0, False, False, '\x00\x00'), (0, 0, False, False, '\x00\x00'), (0, 0, True, False, '\x00\x00'), (77.0, 1, False, False, '\x03\x02'), (77.0, 1, True, False, '\x02\x03'), (770, 0, False, False, '\x03\x02'), (770, 0, True, False, '\x02\x03'), (65535, 0, False, False, '\xff\xff'), (65535, 0, True, False, '\xff\xff'), (770, 0, False, True, '\x03\x02'), (77.0, 1, False, True, '\x03\x02'), (0.0, 0, False, True, '\x00\x00'), (0.0, 3, False, True, '\x00\x00'), (-1, 0, False, True, '\xff\xff'), (-1, 1, False, True, '\xff\xf6'), (-77, 0, False, True, '\xff\xb3'), (-770, 0, False, True, '\xfc\xfe'), (-77, 1, False, True, '\xfc\xfe'), (-32768, 0, False, True, '\x80\x00'), (32767, 0, False, True, '\x7f\xff')]
testSanity()[source]
class test_minimalmodbus.TestLongToBytestring(methodName='runTest')[source]
knownValues = [(0, False, 2, '\x00\x00\x00\x00'), (0, True, 2, '\x00\x00\x00\x00'), (1, False, 2, '\x00\x00\x00\x01'), (1, True, 2, '\x00\x00\x00\x01'), (2, False, 2, '\x00\x00\x00\x02'), (2, True, 2, '\x00\x00\x00\x02'), (75000, False, 2, '\x00\x01$\xf8'), (75000, True, 2, '\x00\x01$\xf8'), (1000000, False, 2, '\x00\x0fB@'), (1000000, True, 2, '\x00\x0fB@'), (2147483647, False, 2, '\x7f\xff\xff\xff'), (2147483647, True, 2, '\x7f\xff\xff\xff'), (2147483648, False, 2, '\x80\x00\x00\x00'), (4294967295, False, 2, '\xff\xff\xff\xff'), (-1, True, 2, '\xff\xff\xff\xff'), (-2147483648, True, 2, '\x80\x00\x00\x00'), (-200000000, True, 2, '\xf4\x14>\x00')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestBytestringToLong(methodName='runTest')[source]
knownValues = [(0, False, 2, '\x00\x00\x00\x00'), (0, True, 2, '\x00\x00\x00\x00'), (1, False, 2, '\x00\x00\x00\x01'), (1, True, 2, '\x00\x00\x00\x01'), (2, False, 2, '\x00\x00\x00\x02'), (2, True, 2, '\x00\x00\x00\x02'), (75000, False, 2, '\x00\x01$\xf8'), (75000, True, 2, '\x00\x01$\xf8'), (1000000, False, 2, '\x00\x0fB@'), (1000000, True, 2, '\x00\x0fB@'), (2147483647, False, 2, '\x7f\xff\xff\xff'), (2147483647, True, 2, '\x7f\xff\xff\xff'), (2147483648, False, 2, '\x80\x00\x00\x00'), (4294967295, False, 2, '\xff\xff\xff\xff'), (-1, True, 2, '\xff\xff\xff\xff'), (-2147483648, True, 2, '\x80\x00\x00\x00'), (-200000000, True, 2, '\xf4\x14>\x00')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityLong(methodName='runTest')[source]
knownValues = [(0, False, 2, '\x00\x00\x00\x00'), (0, True, 2, '\x00\x00\x00\x00'), (1, False, 2, '\x00\x00\x00\x01'), (1, True, 2, '\x00\x00\x00\x01'), (2, False, 2, '\x00\x00\x00\x02'), (2, True, 2, '\x00\x00\x00\x02'), (75000, False, 2, '\x00\x01$\xf8'), (75000, True, 2, '\x00\x01$\xf8'), (1000000, False, 2, '\x00\x0fB@'), (1000000, True, 2, '\x00\x0fB@'), (2147483647, False, 2, '\x7f\xff\xff\xff'), (2147483647, True, 2, '\x7f\xff\xff\xff'), (2147483648, False, 2, '\x80\x00\x00\x00'), (4294967295, False, 2, '\xff\xff\xff\xff'), (-1, True, 2, '\xff\xff\xff\xff'), (-2147483648, True, 2, '\x80\x00\x00\x00'), (-200000000, True, 2, '\xf4\x14>\x00')]
testSanity()[source]
class test_minimalmodbus.TestFloatToBytestring(methodName='runTest')[source]
knownValues = [(1, 2, '?\x80\x00\x00'), (1.0, 2, '?\x80\x00\x00'), (1.0, 2, '?\x80\x00\x00'), (1.1, 2, '?\x8c\xcc\xcd'), (100, 2, 'B\xc8\x00\x00'), (100.0, 2, 'B\xc8\x00\x00'), (100000.0, 2, 'G\xc3P\x00'), (1100000000.0, 2, 'N\x83!V'), (1e+16, 2, 'Z\x0e\x1b\xca'), (1.5e+16, 2, 'ZU)\xaf'), (3.65e+30, 2, 'r8G%'), (-1.1, 2, '\xbf\x8c\xcc\xcd'), (-2, 2, '\xc0\x00\x00\x00'), (-3.6e+30, 2, '\xf25\xc0\xe9'), (1.0, 4, '?\xf0\x00\x00\x00\x00\x00\x00'), (2, 4, '@\x00\x00\x00\x00\x00\x00\x00'), (1100000000.0, 4, 'A\xd0d*\xc0\x00\x00\x00'), (3.65e+30, 4, 'FG\x08\xe4\x9e/Mb'), (2.42e+300, 4, '~L\xe8\xa5g\x1fF\xa0'), (-1.1, 4, '\xbf\xf1\x99\x99\x99\x99\x99\x9a'), (-2, 4, '\xc0\x00\x00\x00\x00\x00\x00\x00'), (-3.6e+30, 4, '\xc6F\xb8\x1d\x1aC\xb2\x06')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestBytestringToFloat(methodName='runTest')[source]
knownValues = [(1, 2, '?\x80\x00\x00'), (1.0, 2, '?\x80\x00\x00'), (1.0, 2, '?\x80\x00\x00'), (1.1, 2, '?\x8c\xcc\xcd'), (100, 2, 'B\xc8\x00\x00'), (100.0, 2, 'B\xc8\x00\x00'), (100000.0, 2, 'G\xc3P\x00'), (1100000000.0, 2, 'N\x83!V'), (1e+16, 2, 'Z\x0e\x1b\xca'), (1.5e+16, 2, 'ZU)\xaf'), (3.65e+30, 2, 'r8G%'), (-1.1, 2, '\xbf\x8c\xcc\xcd'), (-2, 2, '\xc0\x00\x00\x00'), (-3.6e+30, 2, '\xf25\xc0\xe9'), (1.0, 4, '?\xf0\x00\x00\x00\x00\x00\x00'), (2, 4, '@\x00\x00\x00\x00\x00\x00\x00'), (1100000000.0, 4, 'A\xd0d*\xc0\x00\x00\x00'), (3.65e+30, 4, 'FG\x08\xe4\x9e/Mb'), (2.42e+300, 4, '~L\xe8\xa5g\x1fF\xa0'), (-1.1, 4, '\xbf\xf1\x99\x99\x99\x99\x99\x9a'), (-2, 4, '\xc0\x00\x00\x00\x00\x00\x00\x00'), (-3.6e+30, 4, '\xc6F\xb8\x1d\x1aC\xb2\x06')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityFloat(methodName='runTest')[source]
knownValues = [(1, 2, '?\x80\x00\x00'), (1.0, 2, '?\x80\x00\x00'), (1.0, 2, '?\x80\x00\x00'), (1.1, 2, '?\x8c\xcc\xcd'), (100, 2, 'B\xc8\x00\x00'), (100.0, 2, 'B\xc8\x00\x00'), (100000.0, 2, 'G\xc3P\x00'), (1100000000.0, 2, 'N\x83!V'), (1e+16, 2, 'Z\x0e\x1b\xca'), (1.5e+16, 2, 'ZU)\xaf'), (3.65e+30, 2, 'r8G%'), (-1.1, 2, '\xbf\x8c\xcc\xcd'), (-2, 2, '\xc0\x00\x00\x00'), (-3.6e+30, 2, '\xf25\xc0\xe9'), (1.0, 4, '?\xf0\x00\x00\x00\x00\x00\x00'), (2, 4, '@\x00\x00\x00\x00\x00\x00\x00'), (1100000000.0, 4, 'A\xd0d*\xc0\x00\x00\x00'), (3.65e+30, 4, 'FG\x08\xe4\x9e/Mb'), (2.42e+300, 4, '~L\xe8\xa5g\x1fF\xa0'), (-1.1, 4, '\xbf\xf1\x99\x99\x99\x99\x99\x9a'), (-2, 4, '\xc0\x00\x00\x00\x00\x00\x00\x00'), (-3.6e+30, 4, '\xc6F\xb8\x1d\x1aC\xb2\x06')]
testSanity()[source]
class test_minimalmodbus.TestValuelistToBytestring(methodName='runTest')[source]
knownValues = [([1], 1, '\x00\x01'), ([0, 0], 2, '\x00\x00\x00\x00'), ([1, 2], 2, '\x00\x01\x00\x02'), ([1, 256], 2, '\x00\x01\x01\x00'), ([1, 2, 3, 4], 4, '\x00\x01\x00\x02\x00\x03\x00\x04'), ([1, 2, 3, 4, 5], 5, '\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestBytestringToValuelist(methodName='runTest')[source]
knownValues = [([1], 1, '\x00\x01'), ([0, 0], 2, '\x00\x00\x00\x00'), ([1, 2], 2, '\x00\x01\x00\x02'), ([1, 256], 2, '\x00\x01\x01\x00'), ([1, 2, 3, 4], 4, '\x00\x01\x00\x02\x00\x03\x00\x04'), ([1, 2, 3, 4, 5], 5, '\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityValuelist(methodName='runTest')[source]
knownValues = [([1], 1, '\x00\x01'), ([0, 0], 2, '\x00\x00\x00\x00'), ([1, 2], 2, '\x00\x01\x00\x02'), ([1, 256], 2, '\x00\x01\x01\x00'), ([1, 2, 3, 4], 4, '\x00\x01\x00\x02\x00\x03\x00\x04'), ([1, 2, 3, 4, 5], 5, '\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05')]
testSanity()[source]
class test_minimalmodbus.TestTextstringToBytestring(methodName='runTest')[source]
knownValues = [('A', 1, 'A '), ('AB', 1, 'AB'), ('ABC', 2, 'ABC '), ('ABCD', 2, 'ABCD'), ('A', 16, 'A '), ('A', 32, 'A ')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestBytestringToTextstring(methodName='runTest')[source]
knownValues = [('A', 1, 'A '), ('AB', 1, 'AB'), ('ABC', 2, 'ABC '), ('ABCD', 2, 'ABCD'), ('A', 16, 'A '), ('A', 32, 'A ')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityTextstring(methodName='runTest')[source]
knownValues = [('A', 1, 'A '), ('AB', 1, 'AB'), ('ABC', 2, 'ABC '), ('ABCD', 2, 'ABCD'), ('A', 16, 'A '), ('A', 32, 'A ')]
testSanity()[source]
class test_minimalmodbus.TestPack(methodName='runTest')[source]
knownValues = [(-77, '>h', '\xff\xb3'), (-1, '>h', '\xff\xff'), (-770, '>h', '\xfc\xfe'), (-32768, '>h', '\x80\x00'), (32767, '>h', '\x7f\xff'), (770, '>H', '\x03\x02'), (65535, '>H', '\xff\xff'), (75000, '>l', '\x00\x01$\xf8'), (-1, '>l', '\xff\xff\xff\xff'), (-2147483648, '>l', '\x80\x00\x00\x00'), (-200000000, '>l', '\xf4\x14>\x00'), (1, '>L', '\x00\x00\x00\x01'), (75000, '>L', '\x00\x01$\xf8'), (2147483648, '>L', '\x80\x00\x00\x00'), (2147483647, '>L', '\x7f\xff\xff\xff'), (1.0, '>f', '?\x80\x00\x00'), (100000.0, '>f', 'G\xc3P\x00'), (1e+16, '>f', 'Z\x0e\x1b\xca'), (3.65e+30, '>f', 'r8G%'), (-2, '>f', '\xc0\x00\x00\x00'), (-3.6e+30, '>f', '\xf25\xc0\xe9'), (1.0, '>d', '?\xf0\x00\x00\x00\x00\x00\x00'), (2, '>d', '@\x00\x00\x00\x00\x00\x00\x00'), (1100000000.0, '>d', 'A\xd0d*\xc0\x00\x00\x00'), (3.65e+30, '>d', 'FG\x08\xe4\x9e/Mb'), (2.42e+300, '>d', '~L\xe8\xa5g\x1fF\xa0'), (-1.1, '>d', '\xbf\xf1\x99\x99\x99\x99\x99\x9a'), (-2, '>d', '\xc0\x00\x00\x00\x00\x00\x00\x00')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestUnpack(methodName='runTest')[source]
knownValues = [(-77, '>h', '\xff\xb3'), (-1, '>h', '\xff\xff'), (-770, '>h', '\xfc\xfe'), (-32768, '>h', '\x80\x00'), (32767, '>h', '\x7f\xff'), (770, '>H', '\x03\x02'), (65535, '>H', '\xff\xff'), (75000, '>l', '\x00\x01$\xf8'), (-1, '>l', '\xff\xff\xff\xff'), (-2147483648, '>l', '\x80\x00\x00\x00'), (-200000000, '>l', '\xf4\x14>\x00'), (1, '>L', '\x00\x00\x00\x01'), (75000, '>L', '\x00\x01$\xf8'), (2147483648, '>L', '\x80\x00\x00\x00'), (2147483647, '>L', '\x7f\xff\xff\xff'), (1.0, '>f', '?\x80\x00\x00'), (100000.0, '>f', 'G\xc3P\x00'), (1e+16, '>f', 'Z\x0e\x1b\xca'), (3.65e+30, '>f', 'r8G%'), (-2, '>f', '\xc0\x00\x00\x00'), (-3.6e+30, '>f', '\xf25\xc0\xe9'), (1.0, '>d', '?\xf0\x00\x00\x00\x00\x00\x00'), (2, '>d', '@\x00\x00\x00\x00\x00\x00\x00'), (1100000000.0, '>d', 'A\xd0d*\xc0\x00\x00\x00'), (3.65e+30, '>d', 'FG\x08\xe4\x9e/Mb'), (2.42e+300, '>d', '~L\xe8\xa5g\x1fF\xa0'), (-1.1, '>d', '\xbf\xf1\x99\x99\x99\x99\x99\x9a'), (-2, '>d', '\xc0\x00\x00\x00\x00\x00\x00\x00')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityPackUnpack(methodName='runTest')[source]
knownValues = [(-77, '>h', '\xff\xb3'), (-1, '>h', '\xff\xff'), (-770, '>h', '\xfc\xfe'), (-32768, '>h', '\x80\x00'), (32767, '>h', '\x7f\xff'), (770, '>H', '\x03\x02'), (65535, '>H', '\xff\xff'), (75000, '>l', '\x00\x01$\xf8'), (-1, '>l', '\xff\xff\xff\xff'), (-2147483648, '>l', '\x80\x00\x00\x00'), (-200000000, '>l', '\xf4\x14>\x00'), (1, '>L', '\x00\x00\x00\x01'), (75000, '>L', '\x00\x01$\xf8'), (2147483648, '>L', '\x80\x00\x00\x00'), (2147483647, '>L', '\x7f\xff\xff\xff'), (1.0, '>f', '?\x80\x00\x00'), (100000.0, '>f', 'G\xc3P\x00'), (1e+16, '>f', 'Z\x0e\x1b\xca'), (3.65e+30, '>f', 'r8G%'), (-2, '>f', '\xc0\x00\x00\x00'), (-3.6e+30, '>f', '\xf25\xc0\xe9'), (1.0, '>d', '?\xf0\x00\x00\x00\x00\x00\x00'), (2, '>d', '@\x00\x00\x00\x00\x00\x00\x00'), (1100000000.0, '>d', 'A\xd0d*\xc0\x00\x00\x00'), (3.65e+30, '>d', 'FG\x08\xe4\x9e/Mb'), (2.42e+300, '>d', '~L\xe8\xa5g\x1fF\xa0'), (-1.1, '>d', '\xbf\xf1\x99\x99\x99\x99\x99\x9a'), (-2, '>d', '\xc0\x00\x00\x00\x00\x00\x00\x00')]
testSanity()[source]
class test_minimalmodbus.TestHexencode(methodName='runTest')[source]
knownValues = [('', False, ''), ('7', False, '37'), ('J', False, '4A'), (']', False, '5D'), ('\x04', False, '04'), ('\x04]', False, '045D'), ('mn', False, '6D6E'), ('Katt1', False, '4B61747431'), ('', True, ''), ('7', True, '37'), ('J', True, '4A'), (']', True, '5D'), ('\x04', True, '04'), ('\x04]', True, '04 5D'), ('mn', True, '6D 6E'), ('Katt1', True, '4B 61 74 74 31')]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestHexdecode(methodName='runTest')[source]
knownValues = [('', False, ''), ('7', False, '37'), ('J', False, '4A'), (']', False, '5D'), ('\x04', False, '04'), ('\x04]', False, '045D'), ('mn', False, '6D6E'), ('Katt1', False, '4B61747431'), ('', True, ''), ('7', True, '37'), ('J', True, '4A'), (']', True, '5D'), ('\x04', True, '04'), ('\x04]', True, '04 5D'), ('mn', True, '6D 6E'), ('Katt1', True, '4B 61 74 74 31')]
testKnownValues()[source]
testAllowLowercase()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityHexencodeHexdecode(methodName='runTest')[source]
knownValues = [('', False, ''), ('7', False, '37'), ('J', False, '4A'), (']', False, '5D'), ('\x04', False, '04'), ('\x04]', False, '045D'), ('mn', False, '6D6E'), ('Katt1', False, '4B61747431'), ('', True, ''), ('7', True, '37'), ('J', True, '4A'), (']', True, '5D'), ('\x04', True, '04'), ('\x04]', True, '04 5D'), ('mn', True, '6D 6E'), ('Katt1', True, '4B 61 74 74 31')]
testKnownValues()[source]
testKnownValuesLoop()[source]

Loop through all bytestrings of length two.

class test_minimalmodbus.TestBitResponseToValue(methodName='runTest')[source]
testKnownValues()[source]
testWrongValues()[source]
testWrongType()[source]
class test_minimalmodbus.TestCreateBitPattern(methodName='runTest')[source]
knownValues = [(5, 0, '\x00\x00'), (5, 1, '\xff\x00'), (15, 0, '\x00'), (15, 1, '\x01')]
testKnownValues()[source]
testWrongFunctionCode()[source]
testFunctionCodeNotInteger()[source]
testWrongValue()[source]
testValueNotInteger()[source]
class test_minimalmodbus.TestTwosComplement(methodName='runTest')[source]
knownValues = [(0, 8, 0), (1, 8, 1), (127, 8, 127), (-128, 8, 128), (-127, 8, 129), (-1, 8, 255), (0, 16, 0), (1, 16, 1), (32767, 16, 32767), (-32768, 16, 32768), (-32767, 16, 32769), (-1, 16, 65535)]
testKnownValues()[source]
testOutOfRange()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestFromTwosComplement(methodName='runTest')[source]
knownValues = [(0, 8, 0), (1, 8, 1), (127, 8, 127), (-128, 8, 128), (-127, 8, 129), (-1, 8, 255), (0, 16, 0), (1, 16, 1), (32767, 16, 32767), (-32768, 16, 32768), (-32767, 16, 32769), (-1, 16, 65535)]
testKnownValues()[source]
testOutOfRange()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestSanityTwosComplement(methodName='runTest')[source]
knownValues = [1, 2, 4, 8, 12, 16]
testSanity()[source]
class test_minimalmodbus.TestSetBitOn(methodName='runTest')[source]
knownValues = [(4, 0, 5), (4, 1, 6), (1, 1, 3)]
testKnownValues()[source]
testWrongInputValue()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestCalculateCrcString(methodName='runTest')[source]
knownValues = [('\x02\x07', 'A\x12'), ('ABCDE', '\x0fP')]
testKnownValues()[source]
testCalculationTime()[source]
testNotStringInput()[source]
class test_minimalmodbus.TestCalculateLrcString(methodName='runTest')[source]
knownValues = [('ABCDE', '\xb1'), ('\x02001#\x03', 'G')]
testKnownValues()[source]
testNotStringInput()[source]
class test_minimalmodbus.TestCheckFunctioncode(methodName='runTest')[source]
testCorrectFunctioncode()[source]
testCorrectFunctioncodeNoRange()[source]
testWrongFunctioncode()[source]
testWrongFunctioncodeNoRange()[source]
testWrongFunctioncodeType()[source]
testWrongFunctioncodeListValues()[source]
testWrongListType()[source]
class test_minimalmodbus.TestCheckSlaveaddress(methodName='runTest')[source]
testKnownValues()[source]
testWrongValues()[source]
testNotIntegerInput()[source]
class test_minimalmodbus.TestCheckMode(methodName='runTest')[source]
testKnownValues()[source]
testWrongValues()[source]
testNotIntegerInput()[source]
class test_minimalmodbus.TestCheckRegisteraddress(methodName='runTest')[source]
testKnownValues()[source]
testWrongValues()[source]
testWrongType()[source]
class test_minimalmodbus.TestCheckResponseNumberOfBytes(methodName='runTest')[source]
testCorrectNumberOfBytes()[source]
testWrongNumberOfBytes()[source]
testNotStringInput()[source]
class test_minimalmodbus.TestCheckResponseRegisterAddress(methodName='runTest')[source]
testCorrectResponseRegisterAddress()[source]
testWrongResponseRegisterAddress()[source]
testTooShortString()[source]
testNotString()[source]
testWrongAddress()[source]
testAddressNotInteger()[source]
class test_minimalmodbus.TestCheckResponseNumberOfRegisters(methodName='runTest')[source]
testCorrectResponseNumberOfRegisters()[source]
testWrongResponseNumberOfRegisters()[source]
testTooShortString()[source]
testNotString()[source]
testWrongResponseNumberOfRegistersRange()[source]
testNumberOfRegistersNotInteger()[source]
class test_minimalmodbus.TestCheckResponseWriteData(methodName='runTest')[source]
testCorrectResponseWritedata()[source]
testWrongResponseWritedata()[source]
testNotString()[source]
testTooShortString()[source]
testTooLongString()[source]
class test_minimalmodbus.TestCheckString(methodName='runTest')[source]
testKnownValues()[source]
testTooShort()[source]
testTooLong()[source]
testInconsistentLengthlimits()[source]
testInputNotString()[source]
testNotIntegerInput()[source]
testDescriptionNotString()[source]
class test_minimalmodbus.TestCheckInt(methodName='runTest')[source]
testKnownValues()[source]
testTooLargeValue()[source]
testTooSmallValue()[source]
testInconsistentLimits()[source]
testWrongInputType()[source]
class test_minimalmodbus.TestCheckNumerical(methodName='runTest')[source]
testKnownValues()[source]
testTooLargeValue()[source]
testTooSmallValue()[source]
testInconsistentLimits()[source]
testNotNumericInput()[source]
testDescriptionNotString()[source]
class test_minimalmodbus.TestCheckBool(methodName='runTest')[source]
testKnownValues()[source]
testWrongType()[source]
class test_minimalmodbus.TestGetDiagnosticString(methodName='runTest')[source]
testReturnsString()[source]
class test_minimalmodbus.TestPrintOut(methodName='runTest')[source]
testKnownValues()[source]
testInputNotString()[source]
class test_minimalmodbus.TestDummyCommunication(methodName='runTest')[source]
setUp()[source]
testReadBit()[source]
testReadBitWrongValue()[source]
testReadBitWrongType()[source]
testReadBitWithWrongByteCountResponse()[source]
testReadBitWithNoResponse()[source]
testWriteBit()[source]
testWriteBitWrongValue()[source]
testWriteBitWrongType()[source]
testWriteBitWithWrongRegisternumbersResponse()[source]
testWriteBitWithWrongWritedataResponse()[source]
testReadRegister()[source]
testReadRegisterWrongValue()[source]
testReadRegisterWrongType()[source]
testWriteRegister()[source]
testWriteRegisterWithDecimals()[source]
testWriteRegisterWrongValue()[source]
testWriteRegisterWrongType()[source]
testWriteRegisterWithWrongCrcResponse()[source]
testWriteRegisterSuppressErrorMessageAtWrongCRC()[source]
testWriteRegisterWithWrongSlaveaddressResponse()[source]
testWriteRegisterWithWrongFunctioncodeResponse()[source]
testWriteRegisterWithWrongRegisteraddressResponse()[source]
testWriteRegisterWithWrongRegisternumbersResponse()[source]
testWriteRegisterWithWrongWritedataResponse()[source]
testReadLong()[source]
testReadLongWrongValue()[source]
testReadLongWrongType()[source]
testWriteLong()[source]
testWriteLongWrongValue()[source]
testWriteLongWrongType()[source]
testReadFloat()[source]
testReadFloatWrongValue()[source]
testReadFloatWrongType()[source]
testWriteFloat()[source]
testWriteFloatWrongValue()[source]
testWriteFloatWrongType()[source]
testReadString()[source]
testReadStringWrongValue()[source]
testReadStringWrongType()[source]
testWriteString()[source]
testWriteStringWrongValue()[source]
testWriteStringWrongType()[source]
testReadRegisters()[source]
testReadRegistersWrongValue()[source]
testReadRegistersWrongType()[source]
testWriteRegisters()[source]
testWriteRegistersWrongValue()[source]
testWriteRegistersWrongType()[source]
testGenericCommand()[source]
testGenericCommandWrongValue()[source]
testGenericCommandWrongValueCombinations()[source]
testGenericCommandWrongType()[source]
testPerformcommandKnownResponse()[source]
testPerformcommandWrongSlaveResponse()[source]
testPerformcommandWrongInputValue()[source]
testPerformcommandWrongInputType()[source]
testCommunicateKnownResponse()[source]
testCommunicateWrongType()[source]
testCommunicateNoMessage()[source]
testCommunicateNoResponse()[source]
testCommunicateLocalEcho()[source]
testCommunicateWrongLocalEcho()[source]
testRepresentation()[source]
testReadPortClosed()[source]
testWritePortClosed()[source]
testPortAlreadyOpen()[source]
testPortAlreadyClosed()[source]
tearDown()[source]
class test_minimalmodbus.TestDummyCommunicationOmegaSlave1(methodName='runTest')[source]
setUp()[source]
testReadBit()[source]
testWriteBit()[source]
testReadRegister()[source]
testWriteRegister()[source]
tearDown()[source]
class test_minimalmodbus.TestDummyCommunicationOmegaSlave10(methodName='runTest')[source]
setUp()[source]
testReadBit()[source]
testWriteBit()[source]
testReadRegister()[source]
testWriteRegister()[source]
tearDown()[source]
class test_minimalmodbus.TestDummyCommunicationDTB4824_RTU(methodName='runTest')[source]
setUp()[source]
testReadBit()[source]
testWriteBit()[source]
testReadBits()[source]
testReadRegister()[source]
testReadRegisters()[source]
testWriteRegister()[source]
tearDown()[source]
class test_minimalmodbus.TestDummyCommunicationDTB4824_ASCII(methodName='runTest')[source]
setUp()[source]
testReadBit()[source]
testWriteBit()[source]
testReadBits()[source]
testReadRegister()[source]
testReadRegisters()[source]
testWriteRegister()[source]
tearDown()[source]
class test_minimalmodbus.TestDummyCommunicationWithPortClosure(methodName='runTest')[source]
setUp()[source]
testReadRegisterSeveralTimes()[source]
testPortAlreadyOpen()[source]
testPortAlreadyClosed()[source]
tearDown()[source]
class test_minimalmodbus.TestVerboseDummyCommunicationWithPortClosure(methodName='runTest')[source]
setUp()[source]
testReadRegister()[source]
tearDown()[source]
class test_minimalmodbus.TestDummyCommunicationDebugmode(methodName='runTest')[source]
setUp()[source]
testReadRegister()[source]
tearDown()[source]
class test_minimalmodbus.TestDummyCommunicationHandleLocalEcho(methodName='runTest')[source]
setUp()[source]
testReadRegister()[source]
testReadRegisterWrongEcho()[source]
tearDown()[source]
test_minimalmodbus.WRONG_ASCII_RESPONSES = {}

A dictionary of respones from a dummy instrument.

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