def test_close_and_terminate(): """Sends 'exit' and terminates the pexpect connection object.""" runner = Bladerunner() sshc = Mock() runner.close(sshc, True) sshc.sendline.assert_called_once_with("exit") assert sshc.terminate.called
def test_close_keep_open(pexpect_exceptions): """Ensure we can close a connection inside another, for jumpboxes.""" runner = Bladerunner() sshc = Mock() # exceptions are ignored here, we hope we're back on the jumpbox sshc.expect = Mock(side_effect=pexpect_exceptions("mock exception")) runner.close(sshc, False) sshc.sendline.assert_called_once_with("exit") sshc.expect.assert_called_once_with( runner.options["shell_prompts"] + runner.options["extra_prompts"], runner.options["cmd_timeout"], )