Skip to content

Commit 8dafbff

Browse files
committed
Revert "Local EmcyConsumer in tests."
This reverts commit 0dabc9e.
1 parent 0dabc9e commit 8dafbff

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

‎test/test_emcy.py‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import can
77

88
import canopen
9-
import canopen.emcy
109

1110

1211
TIMEOUT = 0.1
@@ -313,6 +312,8 @@ def setUp(self):
313312
self.rx_net.connect()
314313
self.producer = canopen.emcy.EmcyProducer(0x081)
315314
self.producer.network = self.net
315+
self.consumer = canopen.emcy.EmcyConsumer()
316+
self.rx_net.subscribe(0x081, self.consumer.on_emcy)
316317

317318
def tearDown(self):
318319
self.net.disconnect()
@@ -322,18 +323,16 @@ def tearDown(self):
322323

323324
def test_producer_consumer_integration(self):
324325
"""Test that producer and consumer work together."""
325-
consumer = canopen.emcy.EmcyConsumer()
326-
self.rx_net.subscribe(0x081, consumer.on_emcy)
327326
received_errors = []
328-
consumer.add_callback(lambda err: received_errors.append(err))
327+
self.consumer.add_callback(lambda err: received_errors.append(err))
329328
with (
330329
self.assertLogs(level=logging.INFO),
331330
mock_rx_thread(
332-
consumer,
331+
self.consumer,
333332
lambda: self.producer.send(0x2001, 0x02, b'\x01\x02\x03\x04\x05'),
334333
),
335334
):
336-
err = consumer.wait(0x2001, timeout=TIMEOUT)
335+
err = self.consumer.wait(0x2001, timeout=TIMEOUT)
337336
self.assertIsNotNone(err)
338337
self.assertEqual(err.code, 0x2001)
339338
self.assertEqual(err.register, 0x02)
@@ -342,24 +341,22 @@ def test_producer_consumer_integration(self):
342341

343342
def test_producer_reset_consumer_integration(self):
344343
"""Test producer reset clears consumer active errors."""
345-
consumer = canopen.emcy.EmcyConsumer()
346-
self.rx_net.subscribe(0x081, consumer.on_emcy)
347344
with (
348345
self.assertLogs(level=logging.INFO),
349346
mock_rx_thread(
350-
consumer,
347+
self.consumer,
351348
lambda: self.producer.send(0x2001, 0x02, b'\x01\x02\x03\x04\x05'),
352349
),
353350
):
354-
consumer.wait(0x2001, timeout=TIMEOUT)
355-
self.assertEqual(len(consumer.active), 1)
351+
self.consumer.wait(0x2001, timeout=TIMEOUT)
352+
self.assertEqual(len(self.consumer.active), 1)
356353
with (
357354
self.assertLogs(level=logging.INFO),
358-
mock_rx_thread(consumer, self.producer.reset),
355+
mock_rx_thread(self.consumer, self.producer.reset),
359356
):
360-
self.assertIsNotNone(consumer.wait(timeout=TIMEOUT))
361-
self.assertEqual(len(consumer.active), 0)
362-
self.assertEqual(len(consumer.log), 2)
357+
self.assertIsNotNone(self.consumer.wait(timeout=TIMEOUT))
358+
self.assertEqual(len(self.consumer.active), 0)
359+
self.assertEqual(len(self.consumer.log), 2)
363360

364361

365362
if __name__ == "__main__":

0 commit comments

Comments
 (0)