"""Guards that stop one bad YouTube answer from cascading: the playlist-push circuit breaker.""" from app.sync.playlists import _Breaker class TestBreaker: def test_open_until_the_limit_is_reached(self): b = _Breaker(limit=3) for _ in range(2): b.hit(False) assert b.open() b.hit(False) assert not b.open() and b.tripped def test_a_success_re_arms_the_streak(self): b = _Breaker(limit=3) b.hit(False) b.hit(False) b.hit(True) # one write went through — this isn't an account-wide failure b.hit(False) b.hit(False) assert b.open() def test_stays_tripped_once_tripped(self): b = _Breaker(limit=2) b.hit(False) b.hit(False) b.hit(True) assert not b.open()