<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> from salt . modules import cmdmod <EOL> from salt . exceptions import CommandExecutionError <EOL> from salt . log import LOG_LEVELS <EOL> from salttesting import TestCase , skipIf <EOL> from salttesting . mock import ( <EOL> mock_open , <EOL> MagicMock , <EOL> NO_MOCK , <EOL> NO_MOCK_REASON , <EOL> patch <EOL> ) <EOL> from salttesting . helpers import ensure_in_syspath <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> cmdmod . __grains__ = { } <EOL> DEFAULT_SHELL = '<STR_LIT>' <EOL> MOCK_SHELL_FILE = '<STR_LIT>' '<STR_LIT:\n>' '<STR_LIT>' <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class CMDMODTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> mock_loglevels = { '<STR_LIT:info>' : '<STR_LIT:foo>' , '<STR_LIT:all>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT:bar>' , <EOL> '<STR_LIT>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT:bar>' , '<STR_LIT:error>' : '<STR_LIT:bar>' , <EOL> '<STR_LIT>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT:bar>' } <EOL> def test_render_cmd_no_template ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertEqual ( cmdmod . _render_cmd ( '<STR_LIT:foo>' , '<STR_LIT:bar>' , None ) , <EOL> ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) <EOL> def test_render_cmd_unavailable_engine ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , <EOL> cmdmod . _render_cmd , <EOL> '<STR_LIT>' , '<STR_LIT:bar>' , '<STR_LIT>' ) <EOL> def test_check_loglevel_bad_level ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( LOG_LEVELS , self . mock_loglevels ) : <EOL> self . assertEqual ( cmdmod . _check_loglevel ( level = '<STR_LIT>' ) , '<STR_LIT:foo>' ) <EOL> def test_check_loglevel_bad_level_not_str ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( LOG_LEVELS , self . mock_loglevels ) : <EOL> self . assertEqual ( cmdmod . _check_loglevel ( level = <NUM_LIT:1000> ) , '<STR_LIT:foo>' ) <EOL> def test_check_loglevel_quiet ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( LOG_LEVELS , self . mock_loglevels ) : <EOL> self . assertEqual ( cmdmod . _check_loglevel ( level = '<STR_LIT>' ) , None ) <EOL> def test_check_loglevel_utils_quite ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( LOG_LEVELS , self . mock_loglevels ) : <EOL> self . assertEqual ( cmdmod . _check_loglevel ( quiet = True ) , None ) <EOL> def test_parse_env_not_env ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertEqual ( cmdmod . _parse_env ( None ) , { } ) <EOL> def test_parse_env_list ( self ) : <EOL> '''<STR_LIT>''' <EOL> ret = { '<STR_LIT:foo>' : None , '<STR_LIT:bar>' : None } <EOL> self . assertEqual ( ret , cmdmod . _parse_env ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) ) <EOL> def test_parse_env_dict ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertEqual ( cmdmod . _parse_env ( '<STR_LIT:test>' ) , { } ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> def test_run_shell_is_not_file ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> def test_run_shell_file_no_access ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_run_runas_with_windows ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . dict ( cmdmod . __grains__ , { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> self . assertRaises ( CommandExecutionError , <EOL> cmdmod . _run , <EOL> '<STR_LIT:foo>' , '<STR_LIT:bar>' , runas = '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_run_user_not_available ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' , '<STR_LIT:bar>' , runas = '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_run_zero_umask ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' , '<STR_LIT:bar>' , umask = <NUM_LIT:0> ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_run_invalid_umask ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' , '<STR_LIT:bar>' , umask = '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_run_invalid_cwd_not_abs_path ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_run_invalid_cwd_not_dir ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( side_effect = OSError ) ) <EOL> def test_run_no_vt_os_error ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( side_effect = IOError ) ) <EOL> def test_run_no_vt_io_error ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertRaises ( CommandExecutionError , cmdmod . _run , '<STR_LIT:foo>' ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_run ( self ) : <EOL> '''<STR_LIT>''' <EOL> ret = cmdmod . _run ( '<STR_LIT:foo>' , use_vt = True ) . get ( '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT:foo>' , ret ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_is_valid_shell_windows ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertTrue ( cmdmod . _is_valid_shell ( '<STR_LIT:foo>' ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = False ) ) <EOL> def test_is_valid_shell_none ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . assertIsNone ( cmdmod . _is_valid_shell ( '<STR_LIT:foo>' ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_is_valid_shell_available ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch ( '<STR_LIT>' , mock_open ( read_data = MOCK_SHELL_FILE ) ) : <EOL> self . assertTrue ( cmdmod . _is_valid_shell ( '<STR_LIT>' ) ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = True ) ) <EOL> def test_is_valid_shell_unavailable ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch ( '<STR_LIT>' , mock_open ( read_data = MOCK_SHELL_FILE ) ) : <EOL> self . assertFalse ( cmdmod . _is_valid_shell ( '<STR_LIT:foo>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( CMDMODTestCase , needs_daemon = False ) </s>
