mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-12-17 08:00:13 +01:00
fix(lint): improved type checking and code maintainability
This commit is contained in:
parent
83fe527979
commit
40023e93b8
62 changed files with 187 additions and 197 deletions
|
|
@ -3,16 +3,16 @@ from code.web.services import preview_cache as pc
|
|||
|
||||
def _force_interval_elapsed():
|
||||
# Ensure adaptation interval guard passes
|
||||
if pc._LAST_ADAPT_AT is not None: # type: ignore[attr-defined]
|
||||
pc._LAST_ADAPT_AT -= (pc._ADAPT_INTERVAL_S + 1) # type: ignore[attr-defined]
|
||||
if pc._LAST_ADAPT_AT is not None:
|
||||
pc._LAST_ADAPT_AT -= (pc._ADAPT_INTERVAL_S + 1)
|
||||
|
||||
|
||||
def test_ttl_adapts_down_and_up(capsys):
|
||||
# Enable adaptation regardless of env
|
||||
pc._ADAPTATION_ENABLED = True # type: ignore[attr-defined]
|
||||
pc.TTL_SECONDS = pc._TTL_BASE # type: ignore[attr-defined]
|
||||
pc._RECENT_HITS.clear() # type: ignore[attr-defined]
|
||||
pc._LAST_ADAPT_AT = None # type: ignore[attr-defined]
|
||||
pc._ADAPTATION_ENABLED = True
|
||||
pc.TTL_SECONDS = pc._TTL_BASE
|
||||
pc._RECENT_HITS.clear()
|
||||
pc._LAST_ADAPT_AT = None
|
||||
|
||||
# Low hit ratio pattern (~0.1)
|
||||
for _ in range(72):
|
||||
|
|
@ -23,11 +23,11 @@ def test_ttl_adapts_down_and_up(capsys):
|
|||
out1 = capsys.readouterr().out
|
||||
assert "theme_preview_ttl_adapt" in out1, "expected adaptation log for low hit ratio"
|
||||
ttl_after_down = pc.TTL_SECONDS
|
||||
assert ttl_after_down <= pc._TTL_BASE # type: ignore[attr-defined]
|
||||
assert ttl_after_down <= pc._TTL_BASE
|
||||
|
||||
# Force interval elapsed & high hit ratio pattern (~0.9)
|
||||
_force_interval_elapsed()
|
||||
pc._RECENT_HITS.clear() # type: ignore[attr-defined]
|
||||
pc._RECENT_HITS.clear()
|
||||
for _ in range(72):
|
||||
pc.record_request_hit(True)
|
||||
for _ in range(8):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue