<s> import unittest <EOL> from nose . tools import eq_ <EOL> class TestRetrySleeper ( unittest . TestCase ) : <EOL> def _pass ( self ) : <EOL> pass <EOL> def _fail ( self , times = <NUM_LIT:1> ) : <EOL> from kazoo . retry import ForceRetryError <EOL> scope = dict ( times = <NUM_LIT:0> ) <EOL> def inner ( ) : <EOL> if scope [ '<STR_LIT>' ] >= times : <EOL> pass <EOL> else : <EOL> scope [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> raise ForceRetryError ( '<STR_LIT>' ) <EOL> return inner <EOL> def _makeOne ( self , * args , ** kwargs ) : <EOL> from kazoo . retry import KazooRetry <EOL> return KazooRetry ( * args , ** kwargs ) <EOL> def test_reset ( self ) : <EOL> retry = self . _makeOne ( delay = <NUM_LIT:0> , max_tries = <NUM_LIT:2> ) <EOL> retry ( self . _fail ( ) ) <EOL> eq_ ( retry . _attempts , <NUM_LIT:1> ) <EOL> retry . reset ( ) <EOL> eq_ ( retry . _attempts , <NUM_LIT:0> ) <EOL> def test_too_many_tries ( self ) : <EOL> from kazoo . retry import RetryFailedError <EOL> retry = self . _makeOne ( delay = <NUM_LIT:0> ) <EOL> self . assertRaises ( RetryFailedError , retry , self . _fail ( times = <NUM_LIT> ) ) <EOL> eq_ ( retry . _attempts , <NUM_LIT:1> ) <EOL> def test_maximum_delay ( self ) : <EOL> def sleep_func ( _time ) : <EOL> pass <EOL> retry = self . _makeOne ( delay = <NUM_LIT:10> , max_tries = <NUM_LIT:100> , sleep_func = sleep_func ) <EOL> retry ( self . _fail ( times = <NUM_LIT:10> ) ) <EOL> self . assertTrue ( retry . _cur_delay < <NUM_LIT> , retry . _cur_delay ) <EOL> eq_ ( type ( retry . _cur_delay ) , float ) <EOL> def test_copy ( self ) : <EOL> _sleep = lambda t : None <EOL> retry = self . _makeOne ( sleep_func = _sleep ) <EOL> rcopy = retry . copy ( ) <EOL> self . assertTrue ( rcopy . sleep_func is _sleep ) <EOL> class TestKazooRetry ( unittest . TestCase ) : <EOL> def _makeOne ( self , ** kw ) : <EOL> from kazoo . retry import KazooRetry <EOL> return KazooRetry ( ** kw ) <EOL> def test_connection_closed ( self ) : <EOL> from kazoo . exceptions import ConnectionClosedError <EOL> retry = self . _makeOne ( ) <EOL> def testit ( ) : <EOL> raise ConnectionClosedError ( ) <EOL> self . assertRaises ( ConnectionClosedError , retry , testit ) <EOL> def test_session_expired ( self ) : <EOL> from kazoo . exceptions import SessionExpiredError <EOL> retry = self . _makeOne ( max_tries = <NUM_LIT:1> ) <EOL> def testit ( ) : <EOL> raise SessionExpiredError ( ) <EOL> self . assertRaises ( Exception , retry , testit ) </s>
