Exemple #1
0
 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)
Exemple #2
0
 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
Exemple #3
0
 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'
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
 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'
Exemple #7
0
 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'
Exemple #8
0
 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)
Exemple #9
0
 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
Exemple #10
0
 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
Exemple #11
0
 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'
Exemple #12
0
 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
Exemple #13
0
 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
Exemple #14
0
 def test_defaults_to_localhost_name(self):
     conn = local.LocalConnection()
     assert conn.hostname == 'localhost'
Exemple #15
0
 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'
Exemple #16
0
 def test_hostname_gets_ignored(self):
     conn = local.LocalConnection(hostname='node1')
     assert conn.hostname == 'localhost'