Exemple #1
0
# -*- coding: utf-8 -*-
"""Cywinpty tests."""

# yapf: disable

# Third party imports
from winpty.cywinpty import Agent
from winpty.winpty_wrapper import PY2
from winpty.ptyprocess import which
import pytest


# yapf: disable

CMD = which('cmd')
if PY2:
    CMD = unicode(CMD)  # noqa


@pytest.fixture(scope='module')
def agent_fixture(cols, rows):
    agent = Agent(cols, rows)
    return agent


def test_agent_spawn():
    agent = agent_fixture(80, 25)
    succ = agent.spawn(CMD)
    assert succ
    del agent
Exemple #2
0
# -*- coding: utf-8 -*-
"""winpty wrapper tests."""

# Standard library imports
import os
import time

# Third party imports
from winpty import PTY, WinptyError
from winpty.enums import Backend
from winpty.ptyprocess import which
import pytest

CMD = bytes(which('cmd').lower(), 'utf-8')


def pty_factory(backend):
    @pytest.fixture(scope='function')
    def pty_fixture():
        pty = PTY(80, 20, backend=backend)
        loc = bytes(os.getcwd(), 'utf8')
        assert pty.spawn(CMD)
        time.sleep(0.3)
        return pty

    return pty_fixture


conpty_provider = pty_factory(Backend.ConPTY)
winpty_provider = pty_factory(Backend.WinPTY)
Exemple #3
0
    pty.terminate()


def test_intr(pty_fixture):
    pty = pty_fixture(cmd=[sys.executable, 'import time; time.sleep(10)'])
    pty.sendintr()
    assert pty.wait() != 0


def test_send_control(pty_fixture):
    pty = pty_fixture(cmd=[sys.executable, 'import time; time.sleep(10)'])
    pty.sendcontrol('d')
    assert pty.wait() != 0


@pytest.mark.skipif(which('cat') is None, reason="Requires cat on the PATH")
def test_send_eof(pty_fixture):
    cat = pty_fixture('cat')
    cat.sendeof()
    assert cat.wait() == 0


def test_isatty(pty_fixture):
    pty = pty_fixture()
    assert pty.isatty()
    pty.terminate()
    assert not pty.isatty()


def test_wait(pty_fixture):
    pty = pty_fixture(cmd=[sys.executable, '--version'])
Exemple #4
0
# -*- coding: utf-8 -*-
"""winpty wrapper tests."""

# Standard library imports
import os
import time

# Third party imports
from winpty import PTY, WinptyError
from winpty.enums import Backend
from winpty.ptyprocess import which
import pytest

CMD = which('cmd').lower()


def pty_factory(backend):
    if os.environ.get('CI_RUNNING', None) == '1':
        if backend == Backend.ConPTY:
            os.environ['CONPTY_CI'] = '1'
        elif backend == Backend.WinPTY:
            os.environ.pop('CONPTY_CI', None)

    @pytest.fixture(scope='function')
    def pty_fixture():
        pty = PTY(80, 20, backend=backend)
        # loc = bytes(os.getcwd(), 'utf8')
        assert pty.spawn(CMD)
        time.sleep(0.3)
        return pty