<s> try : <EOL> from StringIO import StringIO <EOL> except ImportError : <EOL> from io import StringIO <EOL> import mock <EOL> import pytest <EOL> from dcos . errors import DCOSException <EOL> from dcos . mesos import MesosFile <EOL> from shpkpr . cli import logger <EOL> from shpkpr . files import log_files <EOL> from shpkpr . mesos import MesosClient <EOL> class MockLogger ( logger . Logger ) : <EOL> def __init__ ( self ) : <EOL> self . buffer = StringIO ( ) <EOL> class MockFuture ( object ) : <EOL> def result ( self ) : <EOL> return [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> class MockFutureException ( object ) : <EOL> def result ( self ) : <EOL> raise DCOSException ( "<STR_LIT>" ) <EOL> def test_log_files_no_mesos_files ( ) : <EOL> ctx = MockLogger ( ) <EOL> with pytest . raises ( DCOSException ) : <EOL> log_files ( ctx , [ ] , False , <NUM_LIT:10> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_log_files_single_mesos_file ( mock_util_stream , mock_get_master_state ) : <EOL> ctx = MockLogger ( ) <EOL> _file = MesosFile ( "<STR_LIT>" , dcos_client = MesosClient ( "<STR_LIT>" ) ) <EOL> mock_util_stream . return_value = [ ( MockFuture ( ) , _file ) ] <EOL> mock_get_master_state . return_value = None <EOL> log_files ( ctx , [ _file ] , False , <NUM_LIT:10> ) <EOL> assert ctx . buffer . getvalue ( ) == "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_log_files_unreachable_mesos_file ( mock_util_stream , mock_get_master_state ) : <EOL> ctx = MockLogger ( ) <EOL> _file_1 = MesosFile ( "<STR_LIT>" , dcos_client = MesosClient ( "<STR_LIT>" ) ) <EOL> _file_2 = MesosFile ( "<STR_LIT>" , dcos_client = MesosClient ( "<STR_LIT>" ) ) <EOL> mock_util_stream . return_value = [ ( MockFutureException ( ) , _file_1 ) , ( MockFuture ( ) , _file_2 ) ] <EOL> mock_get_master_state . return_value = None <EOL> log_files ( ctx , [ _file_1 , _file_2 ] , False , <NUM_LIT:10> ) <EOL> assert ctx . buffer . getvalue ( ) == "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" </s>
