mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-13 08:30:49 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
"""Pytest bootstrap: make non-package script dirs importable for these tests.
|
|
|
|
Several helper modules live in standalone script directories (outside
|
|
``python_pkg/``) and are invoked as ``python <file>.py`` rather than imported as
|
|
packages. To unit-test them they must be importable by bare module name, so each
|
|
directory is placed on ``sys.path`` before the tests import them.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
from typing import TYPE_CHECKING
|
|
|
|
import pytest
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable
|
|
|
|
# Repo root is two levels up from this file (linux_configuration/tests/conftest.py).
|
|
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
# Each standalone script directory whose Python modules these tests import.
|
|
_SCRIPT_DIRS = (
|
|
_REPO_ROOT / "meta" / "scripts", # validate_evidence, validate_contract
|
|
_REPO_ROOT / "linux_configuration" / "utils", # fast_count
|
|
_REPO_ROOT
|
|
/ "linux_configuration"
|
|
/ "misc"
|
|
/ "testsAndMisc-bash"
|
|
/ "tools", # transcribe_fw and its helpers
|
|
)
|
|
|
|
for _script_dir in _SCRIPT_DIRS:
|
|
if str(_script_dir) not in sys.path:
|
|
sys.path.insert(0, str(_script_dir))
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_whisper() -> type[FakeWhisper]:
|
|
"""The faster_whisper double, as a fixture (conftest is not importable)."""
|
|
return FakeWhisper
|
|
|
|
|
|
@pytest.fixture
|
|
def importer() -> Callable[[dict[str, object]], object]:
|
|
"""The ``_try_import`` double factory, as a fixture."""
|
|
return fake_importer
|
|
|
|
|
|
class FakeWhisper:
|
|
"""Stand-in for faster_whisper, recording how a model was constructed.
|
|
|
|
``WhisperModel`` is upstream's CamelCase name, so it is exposed through
|
|
``__getattr__`` rather than defined as a method: defining it would mean
|
|
naming a non-PEP8 identifier here just to satisfy a third-party API.
|
|
"""
|
|
|
|
def __init__(self, error: Exception | None = None) -> None:
|
|
self.calls: list[dict[str, object]] = []
|
|
self._error = error
|
|
|
|
def _construct(self, name: str, **kwargs: object) -> object:
|
|
if self._error is not None:
|
|
raise self._error
|
|
self.calls.append({"name": name, **kwargs})
|
|
return object()
|
|
|
|
def __getattr__(self, attr: str) -> object:
|
|
if attr == "WhisperModel":
|
|
return self._construct
|
|
raise AttributeError(attr)
|
|
|
|
|
|
def fake_importer(available: dict[str, object]) -> object:
|
|
"""Return a ``_try_import`` double resolving only the named modules."""
|
|
|
|
def _try(name: str) -> object | None:
|
|
return available.get(name)
|
|
|
|
return _try
|