1- import os
2- import unittest
3- import canopen
4- import logging
51import time
2+ import unittest
63
7- # logging.basicConfig(level=logging.DEBUG)
8-
9- EDS_PATH = os .path .join (os .path .dirname (__file__ ), 'sample.eds' )
4+ import canopen
5+ from .util import SAMPLE_EDS
106
117
128class TestSDO (unittest .TestCase ):
@@ -18,15 +14,15 @@ class TestSDO(unittest.TestCase):
1814 def setUpClass (cls ):
1915 cls .network1 = canopen .Network ()
2016 cls .network1 .connect ("test" , interface = "virtual" )
21- cls .remote_node = cls .network1 .add_node (2 , EDS_PATH )
17+ cls .remote_node = cls .network1 .add_node (2 , SAMPLE_EDS )
2218
2319 cls .network2 = canopen .Network ()
2420 cls .network2 .connect ("test" , interface = "virtual" )
25- cls .local_node = cls .network2 .create_node (2 , EDS_PATH )
21+ cls .local_node = cls .network2 .create_node (2 , SAMPLE_EDS )
2622
27- cls .remote_node2 = cls .network1 .add_node (3 , EDS_PATH )
23+ cls .remote_node2 = cls .network1 .add_node (3 , SAMPLE_EDS )
2824
29- cls .local_node2 = cls .network2 .create_node (3 , EDS_PATH )
25+ cls .local_node2 = cls .network2 .create_node (3 , SAMPLE_EDS )
3026
3127 @classmethod
3228 def tearDownClass (cls ):
@@ -172,68 +168,6 @@ def test_callbacks(self):
172168 self .assertEqual (self ._kwargs ["data" ], b"\x03 \x04 " )
173169
174170
175- class TestNMT (unittest .TestCase ):
176- """
177- Test NMT slave.
178- """
179-
180- @classmethod
181- def setUpClass (cls ):
182- cls .network1 = canopen .Network ()
183- cls .network1 .connect ("test" , interface = "virtual" )
184- cls .remote_node = cls .network1 .add_node (2 , EDS_PATH )
185-
186- cls .network2 = canopen .Network ()
187- cls .network2 .connect ("test" , interface = "virtual" )
188- cls .local_node = cls .network2 .create_node (2 , EDS_PATH )
189-
190- cls .remote_node2 = cls .network1 .add_node (3 , EDS_PATH )
191-
192- cls .local_node2 = cls .network2 .create_node (3 , EDS_PATH )
193-
194- @classmethod
195- def tearDownClass (cls ):
196- cls .network1 .disconnect ()
197- cls .network2 .disconnect ()
198-
199- def test_start_two_remote_nodes (self ):
200- self .remote_node .nmt .state = 'OPERATIONAL'
201- # Line below is just so that we are sure the client have received the command
202- # before we do the check
203- time .sleep (0.1 )
204- slave_state = self .local_node .nmt .state
205- self .assertEqual (slave_state , 'OPERATIONAL' )
206-
207- self .remote_node2 .nmt .state = 'OPERATIONAL'
208- # Line below is just so that we are sure the client have received the command
209- # before we do the check
210- time .sleep (0.1 )
211- slave_state = self .local_node2 .nmt .state
212- self .assertEqual (slave_state , 'OPERATIONAL' )
213-
214- def test_stop_two_remote_nodes_using_broadcast (self ):
215- # This is a NMT broadcast "Stop remote node"
216- # ie. set the node in STOPPED state
217- self .network1 .send_message (0 , [2 , 0 ])
218-
219- # Line below is just so that we are sure the slaves have received the command
220- # before we do the check
221- time .sleep (0.1 )
222- slave_state = self .local_node .nmt .state
223- self .assertEqual (slave_state , 'STOPPED' )
224- slave_state = self .local_node2 .nmt .state
225- self .assertEqual (slave_state , 'STOPPED' )
226-
227- def test_heartbeat (self ):
228- # self.assertEqual(self.remote_node.nmt.state, 'INITIALISING')
229- # self.assertEqual(self.local_node.nmt.state, 'INITIALISING')
230- self .local_node .nmt .state = 'OPERATIONAL'
231- self .local_node .sdo [0x1017 ].raw = 100
232- time .sleep (0.2 )
233- self .assertEqual (self .remote_node .nmt .state , 'OPERATIONAL' )
234-
235- self .local_node .nmt .stop_heartbeat ()
236-
237171class TestPDO (unittest .TestCase ):
238172 """
239173 Test PDO slave.
@@ -243,11 +177,11 @@ class TestPDO(unittest.TestCase):
243177 def setUpClass (cls ):
244178 cls .network1 = canopen .Network ()
245179 cls .network1 .connect ("test" , interface = "virtual" )
246- cls .remote_node = cls .network1 .add_node (2 , EDS_PATH )
180+ cls .remote_node = cls .network1 .add_node (2 , SAMPLE_EDS )
247181
248182 cls .network2 = canopen .Network ()
249183 cls .network2 .connect ("test" , interface = "virtual" )
250- cls .local_node = cls .network2 .create_node (2 , EDS_PATH )
184+ cls .local_node = cls .network2 .create_node (2 , SAMPLE_EDS )
251185
252186 @classmethod
253187 def tearDownClass (cls ):
0 commit comments