File: test_exceptions.py

package info (click to toggle)
pymodbus 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,708 kB
  • sloc: python: 17,594; makefile: 84; sh: 8
file content (38 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
import unittest
from pymodbus.exceptions import *

class SimpleExceptionsTest(unittest.TestCase):
    '''
    This is the unittest for the pymodbus.exceptions module
    '''

    def setUp(self):
        ''' Initializes the test environment '''
        self.exceptions = [
                ModbusException("bad base"),
                ModbusIOException("bad register"),
                ParameterException("bad paramater"),
                NotImplementedException("bad function"),
                ConnectionException("bad connection"),
        ]

    def tearDown(self):
        ''' Cleans up the test environment '''
        pass

    def testExceptions(self):
        ''' Test all module exceptions '''
        for ex in self.exceptions:
            try:
                raise ex
            except ModbusException as ex:
                self.assertTrue("Modbus Error:" in str(ex))
                pass
            else: self.fail("Excepted a ModbusExceptions")

#---------------------------------------------------------------------------#
# Main
#---------------------------------------------------------------------------#
if __name__ == "__main__":
    unittest.main()