fix(tests): remove type: ignore and fix ruff format in toctou step file
CI / push-validation (pull_request) Successful in 22s
CI / build (pull_request) Successful in 29s
CI / lint (pull_request) Successful in 40s
CI / helm (pull_request) Successful in 40s
CI / quality (pull_request) Successful in 43s
CI / typecheck (pull_request) Successful in 1m13s
CI / security (pull_request) Successful in 1m20s
CI / unit_tests (pull_request) Successful in 5m31s
CI / integration_tests (pull_request) Successful in 8m17s
CI / docker (pull_request) Successful in 2m28s
CI / coverage (pull_request) Successful in 8m3s
CI / status-check (pull_request) Successful in 2s
CI / push-validation (pull_request) Successful in 22s
CI / build (pull_request) Successful in 29s
CI / lint (pull_request) Successful in 40s
CI / helm (pull_request) Successful in 40s
CI / quality (pull_request) Successful in 43s
CI / typecheck (pull_request) Successful in 1m13s
CI / security (pull_request) Successful in 1m20s
CI / unit_tests (pull_request) Successful in 5m31s
CI / integration_tests (pull_request) Successful in 8m17s
CI / docker (pull_request) Successful in 2m28s
CI / coverage (pull_request) Successful in 8m3s
CI / status-check (pull_request) Successful in 2s
Replace five # type: ignore comments with setattr() calls (for module attribute monkey-patching) and an Any return type (for _get_memory_engines), eliminating all type suppressions per project zero-tolerance policy. Fix ruff format violations: collapse @when decorator to one line, reformat raise...from split, and reformat assert message wrapping. ISSUES CLOSED: #7566
This commit is contained in:
@@ -26,9 +26,9 @@ def _get_engine_cache_module() -> Any:
|
||||
return m
|
||||
|
||||
|
||||
def _get_memory_engines() -> dict[str, Any]:
|
||||
def _get_memory_engines() -> Any:
|
||||
"""Return the live MEMORY_ENGINES cache dictionary."""
|
||||
return _get_engine_cache_module().MEMORY_ENGINES # type: ignore[no-any-return]
|
||||
return _get_engine_cache_module().MEMORY_ENGINES
|
||||
|
||||
|
||||
def _get_memory_engines_lock() -> Any:
|
||||
@@ -57,11 +57,11 @@ def _clear_memory_engines() -> None:
|
||||
def _restore_locks(ctx: Context) -> None:
|
||||
"""Restore original lock references if the tracking proxy was installed."""
|
||||
if hasattr(ctx, "_engine_cache_module") and hasattr(ctx, "_original_lock"):
|
||||
ctx._engine_cache_module.MEMORY_ENGINES_LOCK = ctx._original_lock # type: ignore[assignment]
|
||||
setattr(ctx._engine_cache_module, "MEMORY_ENGINES_LOCK", ctx._original_lock)
|
||||
if hasattr(ctx._engine_cache_module, "_original_lock_backup"):
|
||||
del ctx._engine_cache_module._original_lock_backup
|
||||
if hasattr(ctx, "_uow_module") and hasattr(ctx, "_original_uow_lock"):
|
||||
ctx._uow_module.MEMORY_ENGINES_LOCK = ctx._original_uow_lock # type: ignore[assignment]
|
||||
setattr(ctx._uow_module, "MEMORY_ENGINES_LOCK", ctx._original_uow_lock)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -117,13 +117,13 @@ def step_track_lock_acquisition(ctx: Context) -> None:
|
||||
counting_lock = _CountingLock()
|
||||
ctx._engine_cache_module = engine_cache_module
|
||||
ctx._original_lock = real_lock
|
||||
engine_cache_module.MEMORY_ENGINES_LOCK = counting_lock # type: ignore[assignment]
|
||||
setattr(engine_cache_module, "MEMORY_ENGINES_LOCK", counting_lock)
|
||||
|
||||
import cleveragents.infrastructure.database.unit_of_work as _uow_module
|
||||
|
||||
ctx._uow_module = _uow_module
|
||||
ctx._original_uow_lock = _uow_module.MEMORY_ENGINES_LOCK
|
||||
_uow_module.MEMORY_ENGINES_LOCK = counting_lock # type: ignore[assignment]
|
||||
setattr(_uow_module, "MEMORY_ENGINES_LOCK", counting_lock)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -146,9 +146,7 @@ def step_access_uow_engine(ctx: Context, url: str) -> None:
|
||||
_restore_locks(ctx)
|
||||
|
||||
|
||||
@when(
|
||||
'{count:d} threads each access the engine cache for "{url}"'
|
||||
)
|
||||
@when('{count:d} threads each access the engine cache for "{url}"')
|
||||
def step_concurrent_cache_access(ctx: Context, count: int, url: str) -> None:
|
||||
"""Directly test the engine cache's lock by calling create_engine in threads.
|
||||
|
||||
@@ -188,9 +186,9 @@ def step_concurrent_cache_access(ctx: Context, count: int, url: str) -> None:
|
||||
t.join()
|
||||
|
||||
if errors:
|
||||
raise AssertionError(
|
||||
f"Worker threads raised exceptions: {errors}"
|
||||
) from errors[0]
|
||||
raise AssertionError(f"Worker threads raised exceptions: {errors}") from errors[
|
||||
0
|
||||
]
|
||||
|
||||
ctx.concurrent_engines = engines
|
||||
|
||||
@@ -202,9 +200,9 @@ def step_concurrent_cache_access(ctx: Context, count: int, url: str) -> None:
|
||||
|
||||
@then("MEMORY_ENGINES_LOCK should be accessible from the engine_cache module")
|
||||
def step_lock_accessible(ctx: Context) -> None:
|
||||
assert hasattr(
|
||||
ctx.engine_cache_module, "MEMORY_ENGINES_LOCK"
|
||||
), "MEMORY_ENGINES_LOCK not found in engine_cache module"
|
||||
assert hasattr(ctx.engine_cache_module, "MEMORY_ENGINES_LOCK"), (
|
||||
"MEMORY_ENGINES_LOCK not found in engine_cache module"
|
||||
)
|
||||
|
||||
|
||||
@then("MEMORY_ENGINES_LOCK should be a threading.Lock instance")
|
||||
|
||||
Reference in New Issue
Block a user