File: test_detect_available_configs.py

package info (click to toggle)
python-can 3.0.0%2Bgithub-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,892 kB
  • sloc: python: 8,014; makefile: 29; sh: 12
file content (58 lines) | stat: -rw-r--r-- 2,088 bytes parent folder | download
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
#!/usr/bin/env python
# coding: utf-8

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

from __future__ import absolute_import

import sys
import unittest
if sys.version_info.major > 2:
    basestring = str

from can import detect_available_configs

from .config import IS_LINUX, IS_CI


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'], basestring)

    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(IS_LINUX and IS_CI, "socketcan is only available on Linux")
    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()


if __name__ == '__main__':
    unittest.main()