Skip to content

Commit 25c6fe0

Browse files
authored
avoid logging socketcan exception on non-linux platforms (#1800)
1 parent 8ea2425 commit 25c6fe0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

can/interfaces/socketcan/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import struct
1010
import subprocess
11+
import sys
1112
from typing import List, Optional, cast
1213

1314
from can import typechecking
@@ -46,6 +47,8 @@ def find_available_interfaces() -> List[str]:
4647
4748
:return: The list of available and active CAN interfaces or an empty list of the command failed
4849
"""
50+
if sys.platform != "linux":
51+
return []
4952

5053
try:
5154
command = ["ip", "-json", "link", "list", "up"]

test/test_socketcan_helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ def test_find_available_interfaces_w_patch(self):
4545

4646
with mock.patch("subprocess.check_output") as check_output:
4747
check_output.return_value = ip_output
48-
ifs = find_available_interfaces()
4948

50-
self.assertEqual(["vcan0", "mycustomCan123"], ifs)
49+
with mock.patch("sys.platform", "linux"):
50+
ifs = find_available_interfaces()
51+
52+
self.assertEqual(["vcan0", "mycustomCan123"], ifs)
5153

5254
def test_find_available_interfaces_exception(self):
5355
with mock.patch("subprocess.check_output") as check_output:

0 commit comments

Comments
 (0)