forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_detect_available_configs.py
More file actions
55 lines (42 loc) · 1.92 KB
/
Copy pathtest_detect_available_configs.py
File metadata and controls
55 lines (42 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# coding: utf-8
"""
This module tests :meth:`can.BusABC._detect_available_configs` and
:meth:`can.BusABC.detect_available_configs`.
"""
import sys
import unittest
from can import detect_available_configs
from .config import IS_LINUX, IS_CI, TEST_INTERFACE_SOCKETCAN
class TestDetectAvailableConfigs(unittest.TestCase):
def test_count_returned(self):
# At least virtual has to always return at least one interface
self.assertGreaterEqual(len(detect_available_configs()), 1)
self.assertEqual(len(detect_available_configs(interfaces=[])), 0)
self.assertGreaterEqual(len(detect_available_configs(interfaces="virtual")), 1)
self.assertGreaterEqual(
len(detect_available_configs(interfaces=["virtual"])), 1
)
self.assertGreaterEqual(len(detect_available_configs(interfaces=None)), 1)
def test_general_values(self):
configs = detect_available_configs()
for config in configs:
self.assertIn("interface", config)
self.assertIn("channel", config)
self.assertIsInstance(config["interface"], str)
def test_content_virtual(self):
configs = detect_available_configs(interfaces="virtual")
for config in configs:
self.assertEqual(config["interface"], "virtual")
def test_content_socketcan(self):
configs = detect_available_configs(interfaces="socketcan")
for config in configs:
self.assertEqual(config["interface"], "socketcan")
@unittest.skipUnless(TEST_INTERFACE_SOCKETCAN, "socketcan is not tested")
def test_socketcan_on_ci_server(self):
configs = detect_available_configs(interfaces="socketcan")
self.assertGreaterEqual(len(configs), 1)
self.assertIn("vcan0", [config["channel"] for config in configs])
# see TestSocketCanHelpers.test_find_available_interfaces() too
if __name__ == "__main__":
unittest.main()