<s> import os , json , tempfile , filecmp <EOL> from nose . tools import assert_raises <EOL> from mock import MagicMock , patch <EOL> import unit <EOL> import synapseclient <EOL> from synapseclient . retry import _with_retry <EOL> from synapseclient . exceptions import * <EOL> def setup ( module ) : <EOL> print ( '<STR_LIT:\n>' ) <EOL> print ( '<STR_LIT>' * <NUM_LIT> ) <EOL> print ( os . path . basename ( __file__ ) ) <EOL> print ( '<STR_LIT>' * <NUM_LIT> ) <EOL> module . syn = unit . syn <EOL> def test_with_retry ( ) : <EOL> retryParams = { "<STR_LIT>" : <NUM_LIT:3> , "<STR_LIT>" : <NUM_LIT:0> } <EOL> response = MagicMock ( ) <EOL> function = MagicMock ( ) <EOL> function . return_value = response <EOL> response . status_code . __eq__ . side_effect = lambda x : x == <NUM_LIT> <EOL> _with_retry ( function , verbose = True , ** retryParams ) <EOL> assert function . call_count == <NUM_LIT:1> <EOL> response . status_code . __eq__ . side_effect = lambda x : x == <NUM_LIT> <EOL> _with_retry ( function , verbose = True , ** retryParams ) <EOL> assert function . call_count == <NUM_LIT:1> + <NUM_LIT:4> <EOL> thirdTimes = [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] <EOL> def theCharm ( x ) : <EOL> if x == <NUM_LIT> : <EOL> count = thirdTimes . pop ( ) <EOL> return count != <NUM_LIT:3> <EOL> return x == <NUM_LIT> <EOL> response . status_code . __eq__ . side_effect = theCharm <EOL> _with_retry ( function , verbose = True , ** retryParams ) <EOL> assert function . call_count == <NUM_LIT:1> + <NUM_LIT:4> + <NUM_LIT:3> <EOL> retryErrorMessages = [ "<STR_LIT>" ] <EOL> retryParams [ "<STR_LIT>" ] = retryErrorMessages <EOL> response . status_code . __eq__ . side_effect = lambda x : x == <NUM_LIT> <EOL> response . headers . __contains__ . reset_mock ( ) <EOL> response . headers . __contains__ . side_effect = lambda x : x == '<STR_LIT>' <EOL> response . headers . get . side_effect = lambda x , default_value : "<STR_LIT:application/json>" if x == '<STR_LIT>' else None <EOL> response . json . return_value = { "<STR_LIT>" : retryErrorMessages [ <NUM_LIT:0> ] } <EOL> _with_retry ( function , ** retryParams ) <EOL> assert response . headers . get . called <EOL> assert function . call_count == <NUM_LIT:1> + <NUM_LIT:4> + <NUM_LIT:3> + <NUM_LIT:4> <EOL> print ( "<STR_LIT>" ) <EOL> def foo ( ) : raise SynapseError ( "<STR_LIT>" ) <EOL> function . side_effect = foo <EOL> assert_raises ( SynapseError , _with_retry , function , ** retryParams ) <EOL> assert function . call_count == <NUM_LIT:1> + <NUM_LIT:4> + <NUM_LIT:3> + <NUM_LIT:4> + <NUM_LIT:1> </s>
