How to use the aioconsole.interact function in aioconsole

To help you get started, we’ve selected a few aioconsole examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vxgmichel / aioconsole / tests / test_interact.py View on Github external
def test_interact_syntax_error(event_loop, monkeypatch):
    with stdcontrol(event_loop, monkeypatch) as (reader, writer):
        writer.write('a b\n')
        writer.stream.close()
        banner = "A BANNER"
        yield from interact(banner=banner, stop=False)
        yield from assert_stream(reader, banner)
        # Skip line
        yield from reader.readline()
        yield from assert_stream(reader, '    a b')
        yield from assert_stream(reader, '      ^', loose=True)
        yield from assert_stream(reader, 'SyntaxError: invalid syntax')
        yield from assert_stream(reader, sys.ps1)
github vxgmichel / aioconsole / tests / test_interact.py View on Github external
def test_interact_keyboard_interrupt(event_loop, monkeypatch, signaling):
    with stdcontrol(event_loop, monkeypatch) as (reader, writer):
        # Start interaction
        banner = "A BANNER"
        task = asyncio.ensure_future(interact(banner=banner, stop=False))
        # Wait for banner
        yield from assert_stream(reader, banner)
        # Send SIGINT
        if sys.platform == 'win32':
            signal.getsignal(signal.SIGINT)(signal.SIGINT, None)
        else:
            os.kill(os.getpid(), signal.SIGINT)
        # Wait for ps1
        yield from assert_stream(reader, sys.ps1)
        yield from assert_stream(reader, "KeyboardInterrupt")
        # Close stdin
        writer.stream.close()
        # Wait for interact to finish
        yield from assert_stream(reader, sys.ps1)
        yield from task
        # Test
github vxgmichel / aioconsole / tests / test_interact.py View on Github external
def test_interact_traceback(event_loop, monkeypatch):
    with stdcontrol(event_loop, monkeypatch) as (reader, writer):
        banner = "A BANNER"
        writer.write('1/0\n')
        writer.stream.close()
        yield from interact(banner=banner, stop=False)
        # Check stderr
        yield from assert_stream(reader, banner)
        yield from assert_stream(
            reader, sys.ps1 + 'Traceback (most recent call last):')
        # Skip 3 (or 5) lines
        for _ in range(3 if compat.PY35 else 5):
            yield from reader.readline()
        # Check stderr
        yield from assert_stream(reader, "ZeroDivisionError: division by zero")
        yield from assert_stream(reader, sys.ps1)
github vxgmichel / aioconsole / tests / test_interact.py View on Github external
def test_interact_simple(event_loop, monkeypatch):
    with stdcontrol(event_loop, monkeypatch) as (reader, writer):
        banner = "A BANNER"
        writer.write('1+1\n')
        writer.stream.close()
        yield from interact(banner=banner, stop=False)
        yield from assert_stream(reader, banner)
        yield from assert_stream(reader, sys.ps1 + '2')
        yield from assert_stream(reader, sys.ps1)