Skip to content

Commit

Permalink
avoid logging socketcan exception on non-linux platforms (#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
zariiii9003 authored Jun 21, 2024
1 parent 8ea2425 commit 25c6fe0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions can/interfaces/socketcan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import struct
import subprocess
import sys
from typing import List, Optional, cast

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

try:
command = ["ip", "-json", "link", "list", "up"]
Expand Down
6 changes: 4 additions & 2 deletions test/test_socketcan_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def test_find_available_interfaces_w_patch(self):

with mock.patch("subprocess.check_output") as check_output:
check_output.return_value = ip_output
ifs = find_available_interfaces()

self.assertEqual(["vcan0", "mycustomCan123"], ifs)
with mock.patch("sys.platform", "linux"):
ifs = find_available_interfaces()

self.assertEqual(["vcan0", "mycustomCan123"], ifs)

def test_find_available_interfaces_exception(self):
with mock.patch("subprocess.check_output") as check_output:
Expand Down

0 comments on commit 25c6fe0

Please sign in to comment.