Example #1
0
    def test_bash(self):
        bash = replwrap.bash()
        res = bash.run_command("time")
        assert 'real' in res, res

        # PAGER should be set to cat, otherwise man hangs
        res = bash.run_command('man sleep', timeout=2)
        assert 'SLEEP' in res, res
Example #2
0
    def test_bash(self):
        bash = replwrap.bash()
        res = bash.run_command("time")
        assert 'real' in res, res

        # PAGER should be set to cat, otherwise man hangs
        res = bash.run_command('man sleep', timeout=2)
        assert 'SLEEP' in res, res
Example #3
0
    def start_process(self):
        if self.repl is not None:
            self.repl.child.terminate()

        if not self.cmd:
            if os.name == 'nt':
                self.cmd = 'cmd'
                self.repl = cmd()
            elif pexpect.which('bash'):
                self.cmd = 'bash'
                self.repl = bash()
            elif pexpect.which('sh'):
                self.cmd = 'sh'
                self.repl = bash(command='sh')
            else:
                msg = "The command was not found or was not executable: sh"
                raise Exception(msg)
Example #4
0
    def start_process(self):
        if self.repl is not None:
            self.repl.child.terminate()

        if not self.cmd:
            if os.name == 'nt':
                self.cmd = 'cmd'
                self.repl = cmd()
            elif pexpect.which('bash'):
                self.cmd = 'bash'
                self.repl = bash()
            elif pexpect.which('sh'):
                self.cmd = 'sh'
                self.repl = bash(command='sh')
            else:
                msg = "The command was not found or was not executable: sh"
                raise Exception(msg)
Example #5
0
    def start_process(self):
        if not self.repl is None:
            self.repl.child.terminate()

        if not self.cmd:
            try:
                pexpect.which('bash')
            except Exception as e:  # pragma: no cover

                if os.name == 'nt':
                    self.cmd = 'cmd'
                    self.repl = cmd()
                else:
                    raise (e)
            else:
                if pexpect.which('bash'):
                    self.cmd = 'bash'
                    self.repl = bash()
                else:
                    self.cmd = 'sh'
                    self.repl = bash(command='sh')
Example #6
0
    def start_process(self):
        if not self.repl is None:
            self.repl.child.terminate()

        if not self.cmd:
            try:
                pexpect.which('bash')
            except Exception as e:  # pragma: no cover

                if os.name == 'nt':
                    self.cmd = 'cmd'
                    self.repl = cmd()
                else:
                    raise(e)
            else:
                if pexpect.which('bash'):
                    self.cmd = 'bash'
                    self.repl = bash()
                else:
                    self.cmd = 'sh'
                    self.repl = bash(command='sh')
Example #7
0
    def test_multiline(self):
        bash = replwrap.bash()
        res = bash.run_command("echo '1 2\n3 4'")
        self.assertEqual(res.strip().splitlines(), ['1 2', '3 4'])

        # Should raise ValueError if input is incomplete
        try:
            bash.run_command("echo '5 6")
        except ValueError:
            pass
        else:
            assert False, "Didn't raise ValueError for incomplete input"

        # Check that the REPL was reset (SIGINT) after the incomplete input
        res = bash.run_command("echo '1 2\n3 4'")
        self.assertEqual(res.strip().splitlines(), ['1 2', '3 4'])
Example #8
0
    def test_multiline(self):
        bash = replwrap.bash()
        res = bash.run_command("echo '1 2\n3 4'")
        self.assertEqual(res.strip().splitlines(), ['1 2', '3 4'])

        # Should raise ValueError if input is incomplete
        try:
            bash.run_command("echo '5 6")
        except ValueError:
            pass
        else:
            assert False, "Didn't raise ValueError for incomplete input"

        # Check that the REPL was reset (SIGINT) after the incomplete input
        res = bash.run_command("echo '1 2\n3 4'")
        self.assertEqual(res.strip().splitlines(), ['1 2', '3 4'])
Example #9
0
    def test_bash(self):
        bash = replwrap.bash()
        res = bash.run_command("time")
        assert 'real' in res, res

        # PAGER should be set to cat, otherwise man hangs
        res = bash.run_command('man sleep', timeout=2)
        assert 'SLEEP' in res, res

        # should handle CR by default
        cmd = r'for i in {1..3};do echo -ne "\r$i"; sleep 1; done'
        res = bash.run_command(cmd)
        assert '\r1\r2\r3' in res

        # should handle CRs in a stream
        res = bash.run_command(cmd, stream_handler=sys.stdout.write)
        assert res == ''

        # should handle lines with a line handler
        logger = get_log()
        res = bash.run_command('echo "1\n2\n3"', line_handler=logger.info)
        assert res == ''
        text = get_log_text(logger)
        assert '1\n2\n3' in text
Example #10
0
    def test_bash(self):
        bash = replwrap.bash()
        res = bash.run_command("time")
        assert 'real' in res, res

        # PAGER should be set to cat, otherwise man hangs
        res = bash.run_command('man sleep', timeout=2)
        assert 'SLEEP' in res, res

        # should handle CR by default
        cmd = r'for i in {1..3};do echo -ne "\r$i"; sleep 1; done'
        res = bash.run_command(cmd)
        assert '\r1\r2\r3' in res

        # should handle CRs in a stream
        res = bash.run_command(cmd, stream_handler=sys.stdout.write)
        assert res == ''

        # should handle lines with a line handler
        logger = get_log()
        res = bash.run_command('echo "1\n2\n3"', line_handler=logger.info)
        assert res == ''
        text = get_log_text(logger)
        assert '1\n2\n3' in text