<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> import datetime <EOL> import itertools <EOL> import unittest <EOL> import phlsys_tryloop <EOL> class Test ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_A_Breathing ( self ) : <EOL> pass <EOL> def test_B_ReturnsResult ( self ) : <EOL> self . assertEqual ( <NUM_LIT:1> , phlsys_tryloop . try_loop_delay ( lambda : <NUM_LIT:1> , [ ] ) ) <EOL> self . assertEqual ( "<STR_LIT>" , phlsys_tryloop . try_loop_delay ( lambda : "<STR_LIT>" , [ ] ) ) <EOL> def test_C_RetriesEachDelay ( self ) : <EOL> class TestException ( Exception ) : <EOL> pass <EOL> counter = [ ] <EOL> def failer ( ) : <EOL> counter . append ( <NUM_LIT:1> ) <EOL> raise TestException ( ) <EOL> numDelays = <NUM_LIT:4> <EOL> delays = [ datetime . timedelta ( ) for _ in range ( <NUM_LIT:0> , numDelays ) ] <EOL> try : <EOL> phlsys_tryloop . try_loop_delay ( failer , delays , TestException ) <EOL> except TestException : <EOL> pass <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . assertEqual ( <NUM_LIT:1> + numDelays , len ( counter ) ) <EOL> def test_D_RaiseThrough ( self ) : <EOL> class TestException ( Exception ) : <EOL> pass <EOL> counter = [ ] <EOL> def failer ( ) : <EOL> counter . append ( <NUM_LIT:1> ) <EOL> raise TypeError ( ) <EOL> numDelays = <NUM_LIT:4> <EOL> delays = [ datetime . timedelta ( ) for _ in range ( <NUM_LIT:0> , numDelays ) ] <EOL> try : <EOL> phlsys_tryloop . try_loop_delay ( failer , delays , TestException ) <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( counter ) ) <EOL> def test_E_CallsOnException ( self ) : <EOL> fail_counter = [ ] <EOL> on_exception_counter = [ ] <EOL> class TestException ( Exception ) : <EOL> pass <EOL> def failer ( ) : <EOL> fail_counter . append ( <NUM_LIT:1> ) <EOL> raise TestException ( ) <EOL> def on_exception ( e , delay ) : <EOL> print ( e ) <EOL> if delay is not None : <EOL> print ( delay . total_seconds ( ) ) <EOL> on_exception_counter . append ( <NUM_LIT:1> ) <EOL> numDelays = <NUM_LIT:4> <EOL> delays = [ datetime . timedelta ( ) for _ in range ( <NUM_LIT:0> , numDelays ) ] <EOL> try : <EOL> phlsys_tryloop . try_loop_delay ( <EOL> failer , delays , onException = on_exception ) <EOL> except TestException : <EOL> pass <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . assertEqual ( <NUM_LIT:1> + numDelays , len ( fail_counter ) ) <EOL> self . assertEqual ( len ( fail_counter ) , len ( on_exception_counter ) ) <EOL> def test_F_ValidLongIncreasingEndlessRetry ( self ) : <EOL> delays = phlsys_tryloop . make_default_endless_retry ( ) <EOL> first_secs = None <EOL> last_secs = None <EOL> for i in itertools . islice ( delays , <NUM_LIT:1000> ) : <EOL> secs = i . total_seconds ( ) <EOL> self . assertGreaterEqual ( secs , <NUM_LIT:0> ) <EOL> self . assertTrue ( last_secs is None or secs >= last_secs ) <EOL> if first_secs is None : <EOL> first_secs = secs <EOL> last_secs = secs <EOL> self . assertGreater ( last_secs , first_secs ) <EOL> def test_G_ValidFiniteShortRetry ( self ) : <EOL> is_empty = True <EOL> for i in phlsys_tryloop . make_default_short_retry ( ) : <EOL> is_empty = False <EOL> secs = i . total_seconds ( ) <EOL> self . assertGreaterEqual ( secs , <NUM_LIT:0> ) <EOL> self . assertLess ( secs , <NUM_LIT> ) <EOL> self . assertFalse ( is_empty ) </s>
