From 7b98982ab69fce18c6ab3f3711d1a0ea1f4fed06 Mon Sep 17 00:00:00 2001 From: Alpamys Date: Thu, 14 May 2026 00:04:29 +0500 Subject: [PATCH] =?UTF-8?q?fix(test):=20v0.53.8=20CI=20hardening=20?= =?UTF-8?q?=E2=80=94=20strip=20ANSI=20+=20use=20=5Frepo=5Froot()=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Five v0.53.8 CI failures (ubuntu/macos × py3.9/3.11/3.12): 1. test_help_lists_hub_flag — Typer's Rich-rendered help wraps long option help across ANSI box-drawing lines; "--hub" appears as "│ --\nhub" in the CI terminal renderer. Strip ANSI + collapse whitespace before asserting. 2-5. test_pyproject_version / test_*_extra_present / test_force_include — used `Path("pyproject.toml")` (relative to cwd). CI invokes pytest from a different cwd than the repo root on at least one matrix entry. Switched to a `_repo_root()` helper that derives from `__file__` (matches v0.43.0 Part D demo_bundles approach). Local re-run: 66/66 v0.53.8 tests pass after the fix. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/test_v0538.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/test_v0538.py b/tests/test_v0538.py index 582dbb7..6de1b97 100644 --- a/tests/test_v0538.py +++ b/tests/test_v0538.py @@ -510,6 +510,15 @@ class TestPackageDataFixtures: # ---------------------------------------------------------------------- +def _strip_ansi(text: str) -> str: + import re as _re + + # Strip ANSI escape sequences AND Rich-wrapping whitespace so we can + # robustly assert on terminal-rendered Typer help output. + out = _re.sub(r"\x1b\[[0-9;]*m", "", text) + return _re.sub(r"\s+", " ", out) + + class TestDataDownloadHubFlag: def test_help_lists_hub_flag(self): from typer.testing import CliRunner @@ -518,7 +527,7 @@ class TestDataDownloadHubFlag: result = CliRunner().invoke(app, ["download", "--help"]) assert result.exit_code == 0 - assert "--hub" in result.output + assert "--hub" in _strip_ansi(result.output) def test_unknown_hub_rejected(self): from typer.testing import CliRunner @@ -529,7 +538,8 @@ class TestDataDownloadHubFlag: app, ["download", "ds", "--hub", "evilcorp"] ) assert result.exit_code != 0 - assert "evilcorp" in result.output or "not supported" in result.output + clean = _strip_ansi(result.output) + assert "evilcorp" in clean or "not supported" in clean def test_modelscope_hub_advisory(self): from typer.testing import CliRunner @@ -540,8 +550,9 @@ class TestDataDownloadHubFlag: app, ["download", "ds", "--hub", "modelscope"] ) assert result.exit_code != 0 - assert "modelscope" in result.output - assert "v0.53.9" in result.output or "download_repo" in result.output + clean = _strip_ansi(result.output) + assert "modelscope" in clean + assert "v0.53.9" in clean or "download_repo" in clean # ---------------------------------------------------------------------- @@ -549,21 +560,30 @@ class TestDataDownloadHubFlag: # ---------------------------------------------------------------------- +def _repo_root() -> Path: + """Resolve the repo root regardless of pytest cwd (CI quirk). + + Tests are run from various cwds across the matrix; ``pyproject.toml`` + sits next to the ``tests/`` folder, so derive from this file's path. + """ + return Path(__file__).resolve().parent.parent + + class TestPyprojectExtras: def test_trackers_extra_present(self): - text = Path("pyproject.toml").read_text(encoding="utf-8") + text = (_repo_root() / "pyproject.toml").read_text(encoding="utf-8") assert "trackers = [" in text assert "mlflow" in text assert "swanlab" in text assert "trackio" in text def test_remote_extra_present(self): - text = Path("pyproject.toml").read_text(encoding="utf-8") + text = (_repo_root() / "pyproject.toml").read_text(encoding="utf-8") assert "remote = [" in text assert "fsspec" in text def test_force_include_package_data(self): - text = Path("pyproject.toml").read_text(encoding="utf-8") + text = (_repo_root() / "pyproject.toml").read_text(encoding="utf-8") assert "_fixtures" in text @@ -579,5 +599,5 @@ class TestVersionBump: assert soup_cli.__version__ == "0.53.8" def test_pyproject_version(self): - text = Path("pyproject.toml").read_text(encoding="utf-8") + text = (_repo_root() / "pyproject.toml").read_text(encoding="utf-8") assert 'version = "0.53.8"' in text