Skip to content

Commit

Permalink
feat: add tests and remove function
Browse files Browse the repository at this point in the history
  • Loading branch information
khauersp committed Jun 10, 2024
1 parent cc19984 commit 7f82bc1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions j1939/electronic_control_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ def remove_bus(self):
"""
self._bus = None

def remove_notifier(self):
"""Remove the notifier from the ECU.
"""
for listener in self._listeners:
self._notifier.remove_listener(listener)
self._notifier = None

def send_pgn(self, data_page, pdu_format, pdu_specific, priority, src_address, data, time_limit=0, frame_format=FrameFormat.FEFF):
"""send a pgn
:param int data_page: data page
Expand Down
23 changes: 22 additions & 1 deletion test/test_ecu.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import time

import can
import j1939
from test_helpers.feeder import Feeder
from test_helpers.conftest import feeder


def receive(feeder):
feeder.ecu.subscribe(on_message)
feeder.inject_messages_into_ecu()
Expand Down Expand Up @@ -165,3 +165,24 @@ def test_broadcast_send_long(feeder):

feeder.send(pdu, 144, pdu[1])

def test_add_bus(feeder):
"""
Test adding and removing a bus to the ECU
"""
bus = can.interface.Bus(interface="virtual", channel=1)
feeder.ecu.add_bus(bus)
assert feeder.ecu._bus == bus
feeder.ecu.remove_bus()
assert feeder.ecu._bus == None

def test_add_notfier(feeder):
"""
Test adding and removing a notifier to the ECU
"""
bus = can.interface.Bus(interface="virtual", channel=1)
feeder.ecu.add_bus(bus)
notifier = can.Notifier(bus=bus, listeners=[])
feeder.ecu.add_notifier(notifier)
assert feeder.ecu._notifier == notifier
feeder.ecu.remove_notifier()
assert feeder.ecu._notifier == None

0 comments on commit 7f82bc1

Please sign in to comment.