~ubuntu-branches/ubuntu/raring/pymodbus/raring-proposed

« back to all changes in this revision

Viewing changes to test/test_device.py

  • Committer: Package Import Robot
  • Author(s): Thomas Bechtold
  • Date: 2012-10-27 12:55:45 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20121027125545-60e94bpztv8vx8om
Tags: 1.1.0-1
* New upstream release.
* debian/control: Add Thomas Bechtold to Uploaders.
* debian/watch: Use github tags for new releases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
import unittest
3
3
from pymodbus.device import *
4
 
from pymodbus.exceptions import *
5
 
from pymodbus.events import *
 
4
from pymodbus.events import ModbusEvent, RemoteReceiveEvent
6
5
from pymodbus.constants import DeviceInformation
7
6
 
8
7
#---------------------------------------------------------------------------#
120
119
    def testModbusControlBlockCounters(self):
121
120
        ''' Tests the MCB counters methods '''
122
121
        self.assertEqual(0x0, self.control.Counter.BusMessage)
123
 
        for i in range(10):
 
122
        for _ in range(10):
124
123
            self.control.Counter.BusMessage += 1
125
124
            self.control.Counter.SlaveMessage += 1
126
125
        self.assertEqual(10, self.control.Counter.BusMessage)
142
141
    def testModbusControlBlockIterator(self):
143
142
        ''' Tests the MCB counters iterator '''
144
143
        self.control.Counter.reset()
145
 
        for name,count in self.control:
 
144
        for _,count in self.control:
146
145
            self.assertEqual(0, count)
147
146
 
148
147
    def testModbusCountersHandlerIterator(self):
149
148
        ''' Tests the MCB counters iterator '''
150
149
        self.control.Counter.reset()
151
 
        for name,count in self.control.Counter:
 
150
        for _,count in self.control.Counter:
152
151
            self.assertEqual(0, count)
153
152
 
154
153
    def testModbusControlBlockCounterSummary(self):
155
154
        ''' Tests retrieving the current counter summary '''
156
155
        self.assertEqual(0x00, self.control.Counter.summary())
157
 
        for i in range(10):
 
156
        for _ in range(10):
158
157
            self.control.Counter.BusMessage += 1
159
158
            self.control.Counter.SlaveMessage += 1
160
159
            self.control.Counter.SlaveNAK += 1
165
164
 
166
165
    def testModbusControlBlockListen(self):
167
166
        ''' Tests the MCB listen flag methods '''
 
167
        
 
168
        self.control.ListenOnly = False        
168
169
        self.assertEqual(self.control.ListenOnly, False)
169
170
        self.control.ListenOnly = not self.control.ListenOnly
170
171
        self.assertEqual(self.control.ListenOnly, True)
171
172
 
172
173
    def testModbusControlBlockDelimiter(self):
173
174
        ''' Tests the MCB delimiter setting methods '''
 
175
        self.control.Delimiter = '\r'
174
176
        self.assertEqual(self.control.Delimiter, '\r')
175
177
        self.control.Delimiter = '='
176
178
        self.assertEqual(self.control.Delimiter, '=')
207
209
 
208
210
    def testAddRemoveMultipleClients(self):
209
211
        ''' Test adding and removing a host '''
210
 
        list = ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
211
 
        self.access.add(list)
212
 
        for host in list:
 
212
        clients = ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
 
213
        self.access.add(clients)
 
214
        for host in clients:
213
215
            self.assertTrue(self.access.check(host))
214
 
        self.access.remove(list)
 
216
        self.access.remove(clients)
215
217
 
216
218
    def testNetworkAccessListIterator(self):
217
219
        ''' Test adding and removing a host '''
218
 
        list = ["127.0.0.1", "192.168.1.1", "192.168.1.2", "192.168.1.3"]
219
 
        self.access.add(list)
 
220
        clients = ["127.0.0.1", "192.168.1.1", "192.168.1.2", "192.168.1.3"]
 
221
        self.access.add(clients)
220
222
        for host in self.access:
221
 
            self.assertTrue(host in list)
222
 
        for host in list:
 
223
            self.assertTrue(host in clients)
 
224
        for host in clients:
223
225
            self.assertTrue(host in self.access)
224
226
 
225
227
    def testClearingControlEvents(self):