diff --git a/scripts/check_new_py_files.py b/scripts/check_new_py_files.py index e8f9844512c..deb63413c47 100644 --- a/scripts/check_new_py_files.py +++ b/scripts/check_new_py_files.py @@ -213,7 +213,7 @@ def get_vcs_added_files(root: str = '.') -> set[str] | None: p = parts[1].strip() if jj_root and not os.path.isabs(p): p = os.path.join(jj_root, p) - added.add(p) + added.add(p.replace(os.sep, '/')) return added # 3. hg @@ -222,9 +222,11 @@ def get_vcs_added_files(root: str = '.') -> set[str] | None: if code == 0: _, out = _run_cmd(['hg', 'status', '--added', '--no-status'], cwd=root) return { - os.path.join(hg_root, f.strip()) - if (hg_root and not os.path.isabs(f.strip())) - else f.strip() + ( + os.path.join(hg_root, f.strip()) + if (hg_root and not os.path.isabs(f.strip())) + else f.strip() + ).replace(os.sep, '/') for f in out.splitlines() if f.strip() } diff --git a/tests/unittests/scripts/test_check_new_py_files.py b/tests/unittests/scripts/test_check_new_py_files.py index cf90d8ff2b5..9f46ce94487 100644 --- a/tests/unittests/scripts/test_check_new_py_files.py +++ b/tests/unittests/scripts/test_check_new_py_files.py @@ -16,6 +16,7 @@ from __future__ import annotations +import ntpath import os import pathlib import subprocess @@ -463,7 +464,15 @@ def fake_run_cmd(cmd: list[str], cwd: str | None = None) -> tuple[int, str]: assert added == {'src/google/adk/agents/_committed.py'} -def test_get_vcs_added_files_jj(monkeypatch: pytest.MonkeyPatch) -> None: +def _patch_windows_paths(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(check_new_py_files.os, 'path', ntpath) + monkeypatch.setattr(check_new_py_files.os, 'sep', '\\') + + +@pytest.mark.parametrize('windows', [False, True]) +def test_get_vcs_added_files_jj( + monkeypatch: pytest.MonkeyPatch, windows: bool +) -> None: def fake_which(cmd: str) -> str | None: return '/usr/bin/' + cmd if cmd == 'jj' else None @@ -476,12 +485,17 @@ def fake_run_cmd(cmd: list[str], cwd: str | None = None) -> tuple[int, str]: monkeypatch.setattr(check_new_py_files.shutil, 'which', fake_which) monkeypatch.setattr(check_new_py_files, '_run_cmd', fake_run_cmd) + if windows: + _patch_windows_paths(monkeypatch) added = check_new_py_files.get_vcs_added_files('.') assert added == {'/workspace/src/google/adk/agents/_jj_agent.py'} -def test_get_vcs_added_files_hg(monkeypatch: pytest.MonkeyPatch) -> None: +@pytest.mark.parametrize('windows', [False, True]) +def test_get_vcs_added_files_hg( + monkeypatch: pytest.MonkeyPatch, windows: bool +) -> None: def fake_which(cmd: str) -> str | None: return '/usr/bin/' + cmd if cmd == 'hg' else None @@ -494,6 +508,8 @@ def fake_run_cmd(cmd: list[str], cwd: str | None = None) -> tuple[int, str]: monkeypatch.setattr(check_new_py_files.shutil, 'which', fake_which) monkeypatch.setattr(check_new_py_files, '_run_cmd', fake_run_cmd) + if windows: + _patch_windows_paths(monkeypatch) added = check_new_py_files.get_vcs_added_files('.') assert added == {'/workspace/src/google/adk/agents/_hg_agent.py'}