def test_brokenchunkwriter(readerwriter_factory, caplog): rw = readerwriter_factory(BrokenChunkWriter) assert rw.reader.read_until_size(len(rw.writer.value)) == rw.writer.value assert rw.writer.rubbish_in_begin in to_bytes(caplog.text) assert (len(rw.writer.value) > CHUNKSIZE) == ( rw.writer.rubbish_in_end in to_bytes(caplog.text))
def __identity_or_raise(self, out): LOGGER.debug('__identity_or_raise: %s, type=%s', out, type(out)) if out is None: raise RunnerTerminalSessionBroken('No output in terminal') steeringstring, pickled = out steeringstring = to_bytes(steeringstring) outobj = self.__try_to_unpickle(to_bytes(pickled), steeringstring) if steeringstring == b'exception': if hasattr(outobj, 'trace'): LOGGER.debug("Remote Traceback: \n%s", ''.join(outobj.trace)) raise outobj # pylint: disable=raising-bad-type if steeringstring == b'timeout': raise RemoteTimeout(response_id=outobj) return _RemoteReturnValue(steeringstring=steeringstring, obj=outobj)
def test_middlerubbish(readerwriter_factory, caplog, badwriter_factory): rw = readerwriter_factory(badwriter_factory) with pytest.raises(ChunkReaderError) as excinfo: rw.reader.read_until_size(len(rw.writer.value)) assert 'Buffer: {!r}'.format(rw.reader.getvalue()) in str(excinfo.value) assert rw.writer.rubbish_in_begin in to_bytes(caplog.text)
def _exec_command(self, cmd): try: ret = self.pythoncmdline.exec_command(cmd) return b'' if ret is None else to_bytes(repr(ret)) except SystemExit: LOGGER.debug('PromptPythonServer: Exiting') raise LineServerExit except Exception as e: # pylint: disable=broad-except return str(ExecCommandErrorObj(e, cmd))
def test_msgpythonshell_send_stdout(msgpythonshell, normal_pythonterminal): out = 'out' msgpythonshell.send_command("{stdout}.write({out})".format( stdout=msgpythonshell.get_stdout_str(), out=repr(out))) msgpythonshell.send_command( "{stdout}.flush()".format(stdout=msgpythonshell.get_stdout_str())) ret = normal_pythonterminal.read_nonblocking(len(out)) assert ret == to_bytes(out), ret assert not msgpythonshell.exec_command('a = 1')
def test_exec_command_client_fails(client_rubbish_msgpythonshell, client_rubbish_pythonterminal_ctx): with client_rubbish_pythonterminal_ctx.in_context(): in_rubbish_out = client_rubbish_msgpythonshell.exec_command('a=1', timeout=1) after_out = client_rubbish_msgpythonshell.exec_command('a=1', timeout=1) for out in [in_rubbish_out, after_out]: assert b'FatalPythonError' not in out assert client_rubbish_pythonterminal_ctx.expected_rubbish not in to_bytes( out)
def test_bash_slow_banner(slowbanner_handler, echo_in_init): i = InteractiveSession() banner = i.spawn(BashShell(tty_echo=echo_in_init, banner_timeout=2)) assert to_bytes(banner).startswith(slowbanner_handler.expected_banner)
def _write(self, s): LOGGER.debug('Writing %s to %d', repr(s), self.outfd) os.write(self.outfd, to_bytes(s))
def token(): return b''.join([to_bytes(chr(c)) for c in random.sample(CHARS, 20)])
import random import string import itertools import pytest from crl.interactivesessions.shells.remotemodules.tokenreader import ( TokenReader, SingleGapMatcher) from crl.interactivesessions.shells.remotemodules.compatibility import ( RANGE, to_bytes, string_conversion_to_bytes) __copyright__ = 'Copyright (C) 2019, Nokia' CHARS = bytearray(to_bytes(string.ascii_letters + string.digits)) @pytest.fixture def token_with_single_gaps(token_with_fixed_gaps, token_with_random_gap): return itertools.chain(token_with_fixed_gaps(), token_with_random_gap()) @pytest.fixture def token_with_fixed_gaps(simple_single_gaps): def gaps(): for prefix in [b'', b'aa']: for t in simple_single_gaps(): yield prefix + t return gaps @pytest.fixture def simple_single_gaps(token):