<s> import os <EOL> import unittest <EOL> try : <EOL> import unittest . mock as mock <EOL> except ImportError : <EOL> import mock <EOL> from cloudbaseinit . plugins . common import base <EOL> from cloudbaseinit . plugins . common import localscripts <EOL> from cloudbaseinit . tests import testutils <EOL> class LocalScriptsPluginTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _localscripts = localscripts . LocalScriptsPlugin ( ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_get_files_in_dir ( self , mock_isfile , mock_listdir ) : <EOL> fake_path = os . path . join ( '<STR_LIT>' , '<STR_LIT:path>' ) <EOL> fake_file_list = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> mock_isfile . return_value = True <EOL> mock_listdir . return_value = fake_file_list <EOL> response = self . _localscripts . _get_files_in_dir ( fake_path ) <EOL> mock_listdir . assert_called_once_with ( fake_path ) <EOL> self . assertEqual ( <EOL> sorted ( os . path . join ( fake_path , f ) for f in fake_file_list ) , <EOL> response ) <EOL> @ mock . patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ testutils . ConfPatcher ( '<STR_LIT>' , <EOL> mock . sentinel . mock_local_scripts_path ) <EOL> @ mock . patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_execute ( self , mock_exec_file , mock_get_files_in_dir , <EOL> mock_get_plugin_return_value ) : <EOL> mock_service = mock . MagicMock ( ) <EOL> fake_path = os . path . join ( '<STR_LIT>' , '<STR_LIT:path>' ) <EOL> mock_get_files_in_dir . return_value = [ fake_path ] * <NUM_LIT:2> <EOL> mock_exec_file . side_effect = [ <NUM_LIT> , <NUM_LIT> ] <EOL> mock_get_plugin_return_value . side_effect = [ <EOL> ( base . PLUGIN_EXECUTE_ON_NEXT_BOOT , False ) , <EOL> ( base . PLUGIN_EXECUTION_DONE , True ) , <EOL> ] <EOL> response = self . _localscripts . execute ( mock_service , shared_data = None ) <EOL> mock_get_files_in_dir . assert_called_once_with ( <EOL> mock . sentinel . mock_local_scripts_path ) <EOL> mock_exec_file . assert_called_with ( fake_path ) <EOL> mock_get_plugin_return_value . assert_any_call ( <NUM_LIT> ) <EOL> mock_get_plugin_return_value . assert_any_call ( <NUM_LIT> ) <EOL> self . assertEqual ( ( base . PLUGIN_EXECUTE_ON_NEXT_BOOT , True ) , response ) </s>
