def test_execute_can_raise_remote_exceptions(self): conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module) with pytest.raises(Exception) as error: assert remote_fake_module.fails() assert 'Exception: failure from fails() function' in str(error.value)
def test_python_executable(self): python_executable = sys.executable conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module, python_executable=python_executable) assert remote_fake_module.remote_interpreter() == python_executable
def test_makes_python_no_ssh(self): conn = local.LocalConnection(sudo=False, eager=False, interpreter='python') conn_string = conn._make_connection_string('srv1', _needs_ssh=lambda x: False) assert conn_string == 'popen//python=python'
def test_execute_wrong_interpreter(self): conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module) remote_fake_module.python_executable = 'python9' with pytest.raises(Exception) as error: remote_fake_module.passes() assert 'Failed to execute command: python9' in str(error.value)
def test_execute_can_raise_unexpected_remote_exceptions(self): conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module) with pytest.raises(Exception) as error: remote_fake_module.unexpected_fail() assert 'error calling "unexpected_fail"' in str(error.value) assert 'Unexpected remote exception' in str(error.value)
def test_does_not_make_sudo_python_with_forced_sudo(self): conn = local.LocalConnection(sudo=True, eager=False, interpreter='python') conn_string = conn._make_connection_string('srv1', _needs_ssh=lambda x: False, use_sudo=False) assert conn_string == 'popen//python=python'
def test_makes_sudo_python_with_ssh_options_ignored(self): conn = local.LocalConnection(sudo=True, eager=False, interpreter='python', ssh_options='-F vagrant_ssh_config') conn_string = conn._make_connection_string('srv1', _needs_ssh=lambda x: True) assert conn_string == 'popen//python=sudo python'
def test_wrong_python_executable(self): python_executable = '/path/to/python' conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module, python_executable=python_executable) with pytest.raises(Exception) as error: remote_fake_module.remote_interpreter() assert 'Failed to execute command: {}'.format(python_executable) in str(error.value)
def test_fallback_interpreter(self, monkeypatch, capsys): monkeypatch.setattr(backends, 'check', lambda *a, **kw: ('', '', 1)) conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module) try: remote_fake_module.passes() except Exception: pass assert remote_fake_module.python_executable is not None
def test_execute_passes_is_none(self): conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module) assert remote_fake_module.passes() is None
def test_which(self, monkeypatch): monkeypatch.setattr(backends, 'check', lambda *a, **kw: (['/usr/bin/python17'], [], 0)) conn = local.LocalConnection() result = backends.get_python_executable(conn) assert result == '/usr/bin/python17'
def test_no_stdout(self, monkeypatch): monkeypatch.setattr(backends, 'check', lambda *a, **kw: ([], [], 0)) conn = local.LocalConnection() result = backends.get_python_executable(conn) assert result == conn.interpreter
def test_execute_returns_casted_boolean(self): conn = local.LocalConnection() conn.remote_import_system = 'json' remote_fake_module = conn.import_module(fake_module) assert remote_fake_module.function(None) is True
def test_defaults_to_localhost_name(self): conn = local.LocalConnection() assert conn.hostname == 'localhost'
def test_detects_python2(self, monkeypatch): monkeypatch.setattr(sys, 'version_info', (2, 7, 11)) conn = local.LocalConnection(sudo=False, eager=False) conn_string = conn._make_connection_string('srv1', _needs_ssh=lambda x: True) assert conn_string == 'popen//python=python2'
def test_hostname_gets_ignored(self): conn = local.LocalConnection(hostname='node1') assert conn.hostname == 'localhost'