Skip to content

Commit

Permalink
#67 Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Oct 5, 2023
1 parent 3297e6c commit f2ece0c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
36 changes: 33 additions & 3 deletions tests/test_circuitbreaker/test_api.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
import asyncio
from typing import cast
from typing import List, cast

import pytest

from hyx.circuitbreaker import consecutive_breaker
from hyx.circuitbreaker import BreakerListener, consecutive_breaker
from hyx.circuitbreaker.context import BreakerContext
from hyx.circuitbreaker.exceptions import BreakerFailing
from hyx.circuitbreaker.states import FailingState, RecoveringState, WorkingState
from hyx.circuitbreaker.states import BreakerState, FailingState, RecoveringState, WorkingState


class Listener(BreakerListener):
def __init__(self) -> None:
self.state_history: List[BreakerState] = []

async def on_working(
self,
context: BreakerContext,
current_state: BreakerState,
next_state: WorkingState,
) -> None:
self.state_history.append(next_state)

async def on_recovering(
self,
context: BreakerContext,
current_state: BreakerState,
next_state: RecoveringState,
) -> None:
self.state_history.append(next_state)

async def on_failing(
self,
context: BreakerContext,
current_state: BreakerState,
next_state: FailingState,
) -> None:
self.state_history.append(next_state)


async def test__circuitbreaker__decorator_context_success() -> None:
Expand Down
6 changes: 5 additions & 1 deletion tests/test_retry/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ async def test__retry__token_bucket_limiter():
exceptions = 0

@bucket_retry(
on=RuntimeError, attempts=attempts, per_time_secs=per_time_secs, bucket_size=bucket_size, listeners=(listener,)
on=RuntimeError,
attempts=attempts,
per_time_secs=per_time_secs,
bucket_size=bucket_size,
listeners=(listener,),
)
async def faulty_func():
nonlocal calls, exceptions
Expand Down

0 comments on commit f2ece0c

Please sign in to comment.