Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions scripts/check_new_py_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down
20 changes: 18 additions & 2 deletions tests/unittests/scripts/test_check_new_py_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from __future__ import annotations

import ntpath
import os
import pathlib
import subprocess
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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'}
Expand Down