@@ -249,6 +249,50 @@ def test_forward_common_fails_without_grad(self, _extractor):
249249class TestBackendHelpers :
250250 """Unit-level checks for _backend utility functions."""
251251
252+ def test_resolve_dp_command_keeps_symlinked_venv_scripts (self , tmp_path , monkeypatch ):
253+ import os
254+ import sys
255+ from pathlib import (
256+ Path ,
257+ )
258+
259+ from dpa_adapt ._backend import (
260+ resolve_dp_command ,
261+ )
262+
263+ exe_name = "dp.exe" if os .name == "nt" else "dp"
264+ python_name = "python.exe" if os .name == "nt" else "python"
265+
266+ real_bin = tmp_path / "real" / "bin"
267+ venv_bin = tmp_path / "venv" / "bin"
268+ real_bin .mkdir (parents = True )
269+ venv_bin .mkdir (parents = True )
270+
271+ real_python = real_bin / python_name
272+ real_python .write_text ("" )
273+ symlink_python = venv_bin / python_name
274+ symlink_python .write_text ("" )
275+
276+ wrong_dp = real_bin / exe_name
277+ wrong_dp .write_text ("" )
278+ expected_dp = venv_bin / exe_name
279+ expected_dp .write_text ("" )
280+
281+ def _fake_resolve (self ):
282+ if self == symlink_python :
283+ return real_python
284+ return self
285+
286+ monkeypatch .setattr (Path , "resolve" , _fake_resolve )
287+ monkeypatch .setattr (sys , "executable" , os .fspath (symlink_python ))
288+ monkeypatch .setattr (
289+ "sysconfig.get_path" ,
290+ lambda name : os .fspath (tmp_path / "other" ) if name == "scripts" else "" ,
291+ )
292+ monkeypatch .setattr ("shutil.which" , lambda name : None )
293+
294+ assert resolve_dp_command () == os .fspath (expected_dp )
295+
252296 def test_get_torch_device_returns_device (self ):
253297 import sys
254298 from unittest .mock import (
0 commit comments