Esempio n. 1
0
def test_interact_simple(event_loop):
    sys.ps1 = "[Hello!]"
    sys.stdin = io.StringIO('1+1\n')
    sys.stderr = io.StringIO()
    banner = "A BANNER"
    expected = '\n'.join((banner, sys.ps1 + '2', sys.ps1)) + '\n'
    yield from interact(banner=banner, stop=False)
    assert sys.stderr.getvalue() == expected
Esempio n. 2
0
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)
Esempio n. 3
0
def test_interact_traceback(event_loop):
    sys.ps1 = "[Hello!] "
    sys.stdin = io.StringIO('1/0\n')
    sys.stderr = io.StringIO()
    banner = "A BANNER"
    yield from interact(banner=banner, stop=False)
    lines = sys.stderr.getvalue().splitlines()
    assert lines[0] == banner
    assert lines[1] == sys.ps1 + "Traceback (most recent call last):"
    index = 5 if compat.PY35 else 7
    assert lines[index] == "ZeroDivisionError: division by zero"
    assert lines[index + 1] == sys.ps1
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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
        assert sys.stdout.getvalue() == ''