def pty_True_uses_paramiko_get_pty(self, remote): chan = remote.expect() c = _Connection('host') r = Remote(context=c) r.run(CMD, pty=True) cols, rows = pty_size() chan.get_pty.assert_called_with(width=cols, height=rows)
def uses_export_prefixing_when_inline_env_is_True(self, remote): chan = remote.expect( cmd="export DEBUG=1 PATH=/opt/bin && {}".format(CMD) ) r = Remote(context=_Connection("host"), inline_env=True) r.run(CMD, env={"PATH": "/opt/bin", "DEBUG": "1"}) assert not chan.update_environment.called
def writes_remote_streams_to_local_streams(self, remote): remote.expect(out=b"hello yes this is dog") c = _Connection('host') r = Remote(context=c) fakeout = StringIO() r.run(CMD, out_stream=fakeout) assert fakeout.getvalue() == "hello yes this is dog"
def pty_True_uses_paramiko_get_pty(self, remote): chan = remote.expect() c = _Connection('host') r = Remote(context=c) r.run(CMD, pty=True) cols, rows = pty_size() chan.get_pty.assert_called_with(width=cols, height=rows)
def writes_remote_streams_to_local_streams(self, remote): remote.expect(out=b"hello yes this is dog") c = _Connection('host') r = Remote(context=c) fakeout = StringIO() r.run(CMD, out_stream=fakeout) assert fakeout.getvalue() == "hello yes this is dog"
def calls_expected_paramiko_bits(self, remote): # remote mocking makes generic sanity checks like "were # get_transport and open_session called", but we also want to make # sure that exec_command got run with our arg to run(). remote.expect(cmd=CMD) c = _Connection('host') r = Remote(context=c) r.run(CMD)
def calls_expected_paramiko_bits(self, remote): # remote mocking makes generic sanity checks like "were # get_transport and open_session called", but we also want to make # sure that exec_command got run with our arg to run(). remote.expect(cmd=CMD) c = _Connection('host') r = Remote(context=c) r.run(CMD)
def return_value_is_Result_subclass_exposing_cxn_used(self, remote): c = _Connection('host') r = Remote(context=c) result = r.run(CMD) assert isinstance(result, Result) # Mild sanity test for other Result superclass bits assert result.ok is True assert result.exited == 0 # Test the attr our own subclass adds assert result.connection is c
def return_value_is_Result_subclass_exposing_cxn_used(self, remote): c = _Connection('host') r = Remote(context=c) result = r.run(CMD) assert isinstance(result, Result) # Mild sanity test for other Result superclass bits assert result.ok is True assert result.exited == 0 # Test the attr our own subclass adds assert result.connection is c
def channel_close_skipped_when_channel_not_even_made(self): # I.e. if obtaining self.channel doesn't even happen (i.e. if # Connection.create_session() dies), we need to account for that # case... class Oops(Exception): pass def oops(): raise Oops cxn = _Connection('host') cxn.create_session = oops r = Remote(context=cxn) # When bug present, this will result in AttributeError because # Remote has no 'channel' try: r.run(CMD) except Oops: pass else: assert False, "Weird, Oops never got raised..."
def channel_close_skipped_when_channel_not_even_made(self): # I.e. if obtaining self.channel doesn't even happen (i.e. if # Connection.create_session() dies), we need to account for that # case... class Oops(Exception): pass def oops(): raise Oops cxn = _Connection('host') cxn.create_session = oops r = Remote(context=cxn) # When bug present, this will result in AttributeError because # Remote has no 'channel' try: r.run(CMD) except Oops: pass else: assert False, "Weird, Oops never got raised..."
def channel_is_closed_normally(self, remote): chan = remote.expect() # I.e. Remote.stop() closes the channel automatically r = Remote(context=_Connection('host')) r.run(CMD) chan.close.assert_called_once_with()
def channel_is_closed_normally(self, remote): chan = remote.expect() # I.e. Remote.stop() closes the channel automatically r = Remote(context=_Connection('host')) r.run(CMD) chan.close.assert_called_once_with()
def _runner(): return Remote(context=_Connection("host"))
def start_sends_given_env_to_paramiko_update_environment(self, remote): chan = remote.expect() c = _Connection("host") r = Remote(context=c) r.run(CMD, pty=True, env={"FOO": "bar"}) chan.update_environment.assert_called_once_with({"FOO": "bar"})
def needs_handle_on_a_Connection(self): c = _Connection("host") assert Remote(context=c).context is c
def send_start_message_sends_exec_command(self): runner = Remote(context=None) runner.channel = Mock() runner.send_start_message(command="whatever") runner.channel.exec_command.assert_called_once_with("whatever")