<s> import pytest <EOL> from mock import patch , MagicMock <EOL> from gitfs . worker . fetch import FetchWorker <EOL> class TestFetchWorker ( object ) : <EOL> def test_work ( self ) : <EOL> mocked_peasant = MagicMock ( ) <EOL> mocked_fetch = MagicMock ( side_effect = ValueError ) <EOL> mocked_fetch_event = MagicMock ( ) <EOL> with patch . multiple ( '<STR_LIT>' , Peasant = mocked_peasant , <EOL> fetch = mocked_fetch_event ) : <EOL> worker = FetchWorker ( ) <EOL> worker . fetch = mocked_fetch <EOL> worker . timeout = <NUM_LIT:5> <EOL> with pytest . raises ( ValueError ) : <EOL> worker . work ( ) <EOL> assert mocked_fetch . call_count == <NUM_LIT:1> <EOL> mocked_fetch_event . wait . assert_called_once_with ( <NUM_LIT:5> ) <EOL> def test_fetch_remote_is_down ( self ) : <EOL> mocked_fetch_ok = MagicMock ( ) <EOL> mocked_fetch = MagicMock ( ) <EOL> mocked_repo = MagicMock ( ) <EOL> mocked_repo . fetch = MagicMock ( side_effect = ValueError ) <EOL> mocked_fetch_ok . set . side_effect = ValueError <EOL> with patch . multiple ( '<STR_LIT>' , <EOL> fetch_successful = mocked_fetch_ok , <EOL> fetch = mocked_fetch ) : <EOL> worker = FetchWorker ( repository = mocked_repo , <EOL> upstream = "<STR_LIT>" , <EOL> credentials = "<STR_LIT>" , <EOL> branch = "<STR_LIT>" ) <EOL> worker . fetch ( ) <EOL> mocked_repo . fetch . assert_called_once_with ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> assert mocked_fetch_ok . clear . call_count == <NUM_LIT:1> <EOL> assert mocked_fetch . clear . call_count == <NUM_LIT:1> <EOL> def test_fetch_in_idle_mode ( self ) : <EOL> mocked_peasant = MagicMock ( ) <EOL> mocked_fetch = MagicMock ( side_effect = ValueError ) <EOL> mocked_fetch_event = MagicMock ( ) <EOL> mocked_idle = MagicMock ( ) <EOL> mocked_idle . is_set . return_value = True <EOL> with patch . multiple ( '<STR_LIT>' , Peasant = mocked_peasant , <EOL> fetch = mocked_fetch_event , idle = mocked_idle ) : <EOL> worker = FetchWorker ( ) <EOL> worker . fetch = mocked_fetch <EOL> worker . timeout = <NUM_LIT:5> <EOL> worker . idle_timeout = <NUM_LIT:20> <EOL> with pytest . raises ( ValueError ) : <EOL> worker . work ( ) <EOL> assert mocked_fetch . call_count == <NUM_LIT:1> <EOL> mocked_fetch_event . wait . assert_called_once_with ( <NUM_LIT:20> ) </s>
