Skip to content

Commit 0362acb

Browse files
committed
Add test case for player.py
1 parent e7a2b04 commit 0362acb

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/test_player.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
# coding: utf-8
3+
4+
"""
5+
This module tests the functions inside of player.py
6+
"""
7+
8+
import unittest
9+
from unittest import mock
10+
from unittest.mock import Mock
11+
import os
12+
import sys
13+
import can
14+
import can.player
15+
16+
from .config import *
17+
18+
19+
class TestPlayerScriptModule(unittest.TestCase):
20+
def setUp(self) -> None:
21+
# Patch VirtualBus object
22+
patcher_virtual_bus = mock.patch("can.interfaces.virtual.VirtualBus", spec=True)
23+
self.MockVirtualBus = patcher_virtual_bus.start()
24+
self.addCleanup(patcher_virtual_bus.stop)
25+
self.mock_virtual_bus = self.MockVirtualBus.return_value
26+
self.mock_virtual_bus.shutdown = Mock()
27+
28+
self.baseargs = [sys.argv[0], "-i", "virtual"]
29+
self.logfile = os.path.join(os.path.dirname(__file__), "data", "test_CanMessage.asc")
30+
31+
def assertSuccessfullCleanup(self):
32+
self.MockVirtualBus.assert_called_once()
33+
34+
def test_play_virtual(self):
35+
sys.argv = self.baseargs + [self.logfile]
36+
can.player.main()
37+
self.assertSuccessfullCleanup()
38+
39+
40+
if __name__ == "__main__":
41+
unittest.main()

0 commit comments

Comments
 (0)