mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:47:03 +01:00
meta/scripts/optimize_vscode.py was 498 lines against a 250-line cap and completely untested, and at that path the repo-wide gate (--cov=python_pkg, fail_under = 100) could not see it. Moved verbatim to python_pkg/vscode_optimizer/_optimize.py - git records a pure rename, and the content is byte-identical to HEAD. The move and the tests are one commit by necessity: any intermediate state with the module under python_pkg/ but uncovered turns every pytest run in the repo red, including ci-mirror on pre-push for unrelated work. Running it by path no longer works after the move (sys.path[0] would be the module's own directory), so __main__.py replaces it, following the existing focus_policy convention rather than a sys.path insert. Nothing invoked the old path: grep over .sh/.desktop/.service/.yml/.py found zero callers. 98 tests reach 100% line and branch coverage. Patching is confined to real boundaries - subprocess.run, the module-level Path, builtins.input, sys.argv - so the forthcoming split has few monkeypatch targets to re-point. Writing the tests surfaced a pre-existing bug, left unfixed here and pinned by a strict xfail: _VENDOR_KW's "ati" key is a substring of "VGA compatible controller", which appears in every lspci display line, so it matches before "intel" is ever tried and Intel iGPUs are misreported as AMD. Verified: python3 -m python_pkg.vscode_optimizer --dry-run reproduces the pre-move 18-change plan and writes nothing; the real settings.json is untouched; repo-wide pytest is 1846 passed at 100%; over-cap files 37 -> 36. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
34 lines
922 B
Python
34 lines
922 B
Python
"""Shared doubles for the hardware-probe tests.
|
|
|
|
``name-tests-test`` requires every module under a tests directory to be named
|
|
``test_*.py``, so helpers shared between test modules live here rather than in
|
|
a helper module.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable
|
|
|
|
|
|
class FakeProc:
|
|
"""Stand-in for the CompletedProcess ``_run`` inspects."""
|
|
|
|
def __init__(self, stdout: str) -> None:
|
|
self.stdout = stdout
|
|
|
|
|
|
def fake_run(mapping: dict[str, str]) -> Callable[..., FakeProc]:
|
|
"""Return a ``subprocess.run`` double keyed on the executable name.
|
|
|
|
Commands absent from *mapping* return empty stdout, which is how the
|
|
probes see a tool that is installed but reports nothing.
|
|
"""
|
|
|
|
def _run(args: list[str], **_kw: object) -> FakeProc:
|
|
return FakeProc(mapping.get(args[0], ""))
|
|
|
|
return _run
|