# Path: metakernel/pexpect.py
# def spawn(command, args=[], timeout=30, maxread=2000,
#           searchwindowsize=None, logfile=None, cwd=None, env=None,
#           ignore_sighup=True, echo=True, encoding='utf-8', **kwargs):
# def which(filename):
# 
# Path: metakernel/replwrap.py
# def u(s):
#     def __init__(self, cmd_or_spawn, prompt_regex, prompt_change_cmd,
#                  new_prompt_regex=PEXPECT_PROMPT,
#                  continuation_prompt_regex=PEXPECT_CONTINUATION_PROMPT,
#                  stdin_prompt_regex=PEXPECT_STDIN_PROMPT,
#                  extra_init_cmd=None,
#                  prompt_emit_cmd=None,
#                  force_prompt_on_continuation=False,
#                  echo=False):
#     def sendline(self, line):
#     def set_prompt(self, prompt_regex, prompt_change_cmd):
#     def _expect_prompt(self, timeout=None):
#     def _expect_prompt_stream(self, expects, timeout=None):
#     def run_command(self, command, timeout=None, stream_handler=None,
#                     line_handler=None, stdin_handler=None):
#     def interrupt(self, continuation=False):
#     def terminate(self):
# def python(command="python"):
# def bash(command="bash", prompt_regex=re.compile('[$#]')):
# def powershell(command='powershell', prompt_regex='>'):
# PEXPECT_PROMPT = u('PEXPECT_PROMPT>')
# PEXPECT_STDIN_PROMPT = u('PEXPECT_PROMPT+')
# PEXPECT_CONTINUATION_PROMPT = u('PEXPECT_PROMPT_')
# class REPLWrapper(object):
# 
# Path: metakernel/tests/utils.py
# def get_log():
#     log = logging.getLogger('test')
#     log.setLevel(logging.DEBUG)
# 
#     for hdlr in log.handlers:
#         log.removeHandler(hdlr)
# 
#     hdlr = logging.StreamHandler(StringIO())
#     hdlr.setLevel(logging.DEBUG)
#     log.addHandler(hdlr)
# 
#     return log
# 
# def get_log_text(obj):
#     """Get the log text from a kernel or a log object."""
#     if isinstance(obj, MetaKernel):
#         log = obj.log
#     else:
#         log = obj
#     return log.handlers[0].stream.getvalue()


import platform
import unittest
import re
import os
import sys
from metakernel import pexpect, replwrap
from metakernel.tests.utils import get_log, get_log_text
        super(REPLWrapTestCase, self).tearDown()
        os.putenv('PS1', self.save_ps1)
        os.putenv('PS2', self.save_ps2)

    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

    def test_multiline(self):

# Path: metakernel/pexpect.py
# def spawn(command, args=[], timeout=30, maxread=2000,
#           searchwindowsize=None, logfile=None, cwd=None, env=None,
#           ignore_sighup=True, echo=True, encoding='utf-8', **kwargs):
# def which(filename):
# 
# Path: metakernel/replwrap.py
# def u(s):
#     def __init__(self, cmd_or_spawn, prompt_regex, prompt_change_cmd,
#                  new_prompt_regex=PEXPECT_PROMPT,
#                  continuation_prompt_regex=PEXPECT_CONTINUATION_PROMPT,
#                  stdin_prompt_regex=PEXPECT_STDIN_PROMPT,
#                  extra_init_cmd=None,
#                  prompt_emit_cmd=None,
#                  force_prompt_on_continuation=False,
#                  echo=False):
#     def sendline(self, line):
#     def set_prompt(self, prompt_regex, prompt_change_cmd):
#     def _expect_prompt(self, timeout=None):
#     def _expect_prompt_stream(self, expects, timeout=None):
#     def run_command(self, command, timeout=None, stream_handler=None,
#                     line_handler=None, stdin_handler=None):
#     def interrupt(self, continuation=False):
#     def terminate(self):
# def python(command="python"):
# def bash(command="bash", prompt_regex=re.compile('[$#]')):
# def powershell(command='powershell', prompt_regex='>'):
# PEXPECT_PROMPT = u('PEXPECT_PROMPT>')
# PEXPECT_STDIN_PROMPT = u('PEXPECT_PROMPT+')
# PEXPECT_CONTINUATION_PROMPT = u('PEXPECT_PROMPT_')
# class REPLWrapper(object):
# 
# Path: metakernel/tests/utils.py
# def get_log():
#     log = logging.getLogger('test')
#     log.setLevel(logging.DEBUG)
# 
#     for hdlr in log.handlers:
#         log.removeHandler(hdlr)
# 
#     hdlr = logging.StreamHandler(StringIO())
#     hdlr.setLevel(logging.DEBUG)
#     log.addHandler(hdlr)
# 
#     return log
# 
# def get_log_text(obj):
#     """Get the log text from a kernel or a log object."""
#     if isinstance(obj, MetaKernel):
#         log = obj.log
#     else:
#         log = obj
#     return log.handlers[0].stream.getvalue()


# Path: metakernel/tests/test_replwrap.py
import platform
import unittest
import re
import os
import sys
from metakernel import pexpect, replwrap
from metakernel.tests.utils import get_log, get_log_text

        super(REPLWrapTestCase, self).tearDown()
        os.putenv('PS1', self.save_ps1)
        os.putenv('PS2', self.save_ps2)

    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

    def test_multiline(self):

        bash = replwrap.bash()