File: test_detect_available_configs.py

package info (click to toggle)
python-can 4.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,372 kB
  • sloc: python: 25,840; makefile: 38; sh: 20
file content (67 lines) | stat: -rw-r--r-- 2,412 bytes parent folder | download | duplicates (2)
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
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python

"""
This module tests :meth:`can.BusABC._detect_available_configs` and
:meth:`can.BusABC.detect_available_configs`.
"""

import unittest

from can import detect_available_configs

from .config import IS_CI, IS_UNIX, 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)

    def test_content_virtual(self):
        configs = detect_available_configs(interfaces="virtual")
        self.assertGreaterEqual(len(configs), 1)
        for config in configs:
            self.assertEqual(config["interface"], "virtual")

    def test_content_udp_multicast(self):
        configs = detect_available_configs(interfaces="udp_multicast")
        for config in configs:
            self.assertEqual(config["interface"], "udp_multicast")

    def test_content_socketcan(self):
        configs = detect_available_configs(interfaces="socketcan")
        for config in configs:
            self.assertEqual(config["interface"], "socketcan")

    def test_count_udp_multicast(self):
        configs = detect_available_configs(interfaces="udp_multicast")
        if IS_UNIX:
            self.assertGreaterEqual(len(configs), 2)
        else:
            self.assertEqual(len(configs), 0)

    @unittest.skipUnless(
        TEST_INTERFACE_SOCKETCAN and IS_CI, "this setup is very specific"
    )
    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()