|
|
@ -90,8 +90,8 @@ def rc_am(mocker, am, mock_os, mock_subprocess):
|
|
|
|
class TestRunCommandArgs:
|
|
|
|
class TestRunCommandArgs:
|
|
|
|
# Format is command as passed to run_command, command to Popen as list, command to Popen as string
|
|
|
|
# Format is command as passed to run_command, command to Popen as list, command to Popen as string
|
|
|
|
ARGS_DATA = (
|
|
|
|
ARGS_DATA = (
|
|
|
|
(['/bin/ls', 'a', 'b', 'c'], ['/bin/ls', 'a', 'b', 'c'], '/bin/ls a b c'),
|
|
|
|
(['/bin/ls', 'a', 'b', 'c'], [b'/bin/ls', b'a', b'b', b'c'], b'/bin/ls a b c'),
|
|
|
|
('/bin/ls a " b" "c "', ['/bin/ls', 'a', ' b', 'c '], '/bin/ls a " b" "c "'),
|
|
|
|
('/bin/ls a " b" "c "', [b'/bin/ls', b'a', b' b', b'c '], b'/bin/ls a " b" "c "'),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# pylint bug: https://github.com/PyCQA/pylint/issues/511
|
|
|
|
# pylint bug: https://github.com/PyCQA/pylint/issues/511
|
|
|
@ -119,13 +119,13 @@ class TestRunCommandCwd:
|
|
|
|
def test_cwd(self, mocker, rc_am):
|
|
|
|
def test_cwd(self, mocker, rc_am):
|
|
|
|
rc_am._os.getcwd.return_value = '/old'
|
|
|
|
rc_am._os.getcwd.return_value = '/old'
|
|
|
|
rc_am.run_command('/bin/ls', cwd='/new')
|
|
|
|
rc_am.run_command('/bin/ls', cwd='/new')
|
|
|
|
assert rc_am._os.chdir.mock_calls == [mocker.call('/new'), mocker.call('/old'), ]
|
|
|
|
assert rc_am._os.chdir.mock_calls == [mocker.call(b'/new'), mocker.call('/old'), ]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
|
|
|
def test_cwd_relative_path(self, mocker, rc_am):
|
|
|
|
def test_cwd_relative_path(self, mocker, rc_am):
|
|
|
|
rc_am._os.getcwd.return_value = '/old'
|
|
|
|
rc_am._os.getcwd.return_value = '/old'
|
|
|
|
rc_am.run_command('/bin/ls', cwd='sub-dir')
|
|
|
|
rc_am.run_command('/bin/ls', cwd='sub-dir')
|
|
|
|
assert rc_am._os.chdir.mock_calls == [mocker.call('/old/sub-dir'), mocker.call('/old'), ]
|
|
|
|
assert rc_am._os.chdir.mock_calls == [mocker.call(b'/old/sub-dir'), mocker.call('/old'), ]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
|
|
|
def test_cwd_not_a_dir(self, mocker, rc_am):
|
|
|
|
def test_cwd_not_a_dir(self, mocker, rc_am):
|
|
|
@ -134,14 +134,6 @@ class TestRunCommandCwd:
|
|
|
|
rc_am.run_command('/bin/ls', cwd='/not-a-dir')
|
|
|
|
rc_am.run_command('/bin/ls', cwd='/not-a-dir')
|
|
|
|
assert rc_am._os.chdir.mock_calls == [mocker.call('/old'), ]
|
|
|
|
assert rc_am._os.chdir.mock_calls == [mocker.call('/old'), ]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
|
|
|
|
|
|
|
def test_cwd_inaccessible(self, rc_am):
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
|
|
|
|
rc_am.run_command('/bin/ls', cwd='/inaccessible')
|
|
|
|
|
|
|
|
assert rc_am.fail_json.called
|
|
|
|
|
|
|
|
args, kwargs = rc_am.fail_json.call_args
|
|
|
|
|
|
|
|
assert kwargs['rc'] == errno.EPERM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestRunCommandPrompt:
|
|
|
|
class TestRunCommandPrompt:
|
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
|
|
|
@pytest.mark.parametrize('stdin', [{}], indirect=['stdin'])
|
|
|
|