mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-14 23:08:26 +00:00
A synced request whose download failed, was interrupted by a restart, or was cancelled by the stall timer goes back to pending after AUTO_DOWNLOAD_RETRY_DAYS (7 by default, 0 turns it off), a few per pass, oldest first. Only what never arrived is retried, the failed release is remembered, and a request is given up on after three failed retries. Downloads cancelled by a person and rejected requests are never retried. Errors count as errors: a search that failed in one source no longer reads as no match, a throttled Hardcover lookup is an error and not a skip, and a request that blows up doesn't abort the pass. Both summaries carry the error count. A request for the same Hardcover book and format is skipped when the history already has a finished or running download for it. A request that finds nothing is searched once a day after three no-match passes, then every two days, up to AUTO_DOWNLOAD_BACKOFF_MAX_DAYS (3 by default, 0 turns it off).
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""Test doubles shared by the core tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
|
|
class FakeConfig:
|
|
"""Stands in for ``shelfmark.core.config.config``, answering from ``values`` only.
|
|
|
|
Unlike the real singleton it never reads the environment or saved settings, so a
|
|
stray ``export`` or a leftover config file can't change what a test sees.
|
|
"""
|
|
|
|
def __init__(self, **values: Any) -> None:
|
|
self.values: dict[str, Any] = dict(values)
|
|
|
|
def get(self, key: str, default: Any = None, user_id: int | None = None) -> Any:
|
|
return self.values.get(key, default)
|
|
|
|
|
|
def capture_log(monkeypatch: pytest.MonkeyPatch, logger: logging.Logger, level: str) -> list[str]:
|
|
"""Collect what ``logger`` emits at ``level`` ("info", "warning", ...), formatted.
|
|
|
|
pytest's ``caplog`` can't see these: ``setup_logger`` loggers don't propagate to
|
|
the root handler it listens on.
|
|
"""
|
|
messages: list[str] = []
|
|
monkeypatch.setattr(logger, level, lambda msg, *args, **_: messages.append(msg % args))
|
|
return messages
|