Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
changeKind: internal
packages:
- "@typespec/http-client-python"
---
Fix `test_sensitive_word` failing on Windows by replacing shell-based search with pure Python `pathlib` implementation.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License.
# ------------------------------------
import os
import re
from subprocess import getoutput
from pathlib import Path
import traceback
from importlib import import_module
Expand Down Expand Up @@ -33,21 +31,25 @@ def test_track_back(client: ScalarClient):
assert "microsoft" not in track_back


def check_sensitive_word(folder: Path, word: str) -> str:
special_folders = ["__pycache__", "pytest_cache"]
if os.name == "nt":
skip_folders = "|".join(special_folders)
output = getoutput(
f"powershell \"ls -r -Path {folder} | where fullname -notmatch '{skip_folders}' | Select-String -Pattern '{word}'\""
).replace("\\", "/")
else:
skip_folders = "{" + ",".join(special_folders) + "}"
output = getoutput(f"grep -ri --exclude-dir={skip_folders} {word} {folder}")
_SKIP_DIRS = {"__pycache__", "pytest_cache", ".pytest_cache"}


def check_sensitive_word(folder: Path, word: str) -> list[str]:
"""Search for a word in all files under folder, return top-level subfolder names that contain it."""
result = set()
for item in re.findall(f"{folder.as_posix()}[^:]+", output.replace("\n", "")):
result.add(Path(item).relative_to(folder).parts[0])
return sorted(list(result))
for path in folder.rglob("*"):
if not path.is_file():
continue
# Skip special directories
if _SKIP_DIRS & set(path.relative_to(folder).parts):
continue
try:
content = path.read_text(encoding="utf-8", errors="ignore")
except (OSError, UnicodeDecodeError):
continue
if word.lower() in content.lower():
result.add(path.relative_to(folder).parts[0])
return sorted(result)


def test_sensitive_word():
Expand Down
Loading