Skip to content

Commit ef1c223

Browse files
committed
allow symlinked ports
Signed-off-by: Maximilian Deubel <[email protected]>
1 parent f192a3d commit ef1c223

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/nrfcredstore/comms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import coloredlogs, logging
2121
import re
2222
import platform
23+
import os
2324
from typing import Tuple, List, Union, Optional
2425

2526
logger = logging.getLogger(__name__)
@@ -210,8 +211,9 @@ def select_device(rtt : bool, serial_number : Optional[Union[str, int]], port :
210211
return (None, select_jlink(jlinks, list_all))
211212

212213
if port:
214+
real_path = os.path.realpath(port)
213215
# Serial ports are unique, so we just check if it exists and try to get a serial number
214-
serial_devices = [x for x in get_comports_fixed_ordering() if x.device == port]
216+
serial_devices = [x for x in get_comports_fixed_ordering() if x.device == real_path]
215217
if len(serial_devices) == 0:
216218
raise Exception(f"No device found with port {port}")
217219
extracted_serial_number = extract_serial_number_from_serial_device(

tests/test_comms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
),
117117
]
118118

119+
@pytest.fixture
120+
def mock_os_realpath():
121+
with patch("nrfcredstore.comms.os.path.realpath", autospec=True) as m:
122+
m.side_effect = lambda x: x # identity function
123+
yield m
119124

120125
@pytest.fixture
121126
def platform_darwin():
@@ -351,7 +356,7 @@ def test_select_device_rtt_true_serial_number_not_found(platform_linux, ports_li
351356
)
352357

353358
# port given
354-
def test_select_device_port_given(platform_linux, ports_linux_multi):
359+
def test_select_device_port_given(platform_linux, ports_linux_multi, mock_os_realpath):
355360
port, serial_number = select_device(
356361
rtt=False, serial_number=None, port="/dev/ttyACM0", list_all=False
357362
)

0 commit comments

Comments
 (0)