test_cywinpty.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- coding: utf-8 -*-
  2. """Cywinpty tests."""
  3. # yapf: disable
  4. # Third party imports
  5. from winpty.cywinpty import Agent
  6. from winpty.winpty_wrapper import PY2
  7. from winpty.ptyprocess import which
  8. import pytest
  9. # yapf: disable
  10. CMD = which('cmd')
  11. if PY2:
  12. CMD = unicode(CMD) # noqa
  13. @pytest.fixture(scope='module')
  14. def agent_fixture():
  15. def _agent_factory(cols, rows):
  16. agent = Agent(cols, rows)
  17. return agent
  18. return _agent_factory
  19. def test_agent_spawn(agent_fixture):
  20. agent = agent_fixture(80, 25)
  21. succ = agent.spawn(CMD)
  22. assert succ
  23. del agent
  24. def test_agent_spawn_fail(agent_fixture):
  25. agent = agent_fixture(80, 25)
  26. try:
  27. agent.spawn(CMD)
  28. except RuntimeError:
  29. pass
  30. def test_agent_spawn_size_fail(agent_fixture):
  31. try:
  32. agent_fixture(80, -25)
  33. except RuntimeError:
  34. pass
  35. def test_agent_resize(agent_fixture):
  36. agent = agent_fixture(80, 25)
  37. agent.set_size(80, 70)
  38. del agent
  39. def test_agent_resize_fail(agent_fixture):
  40. agent = agent_fixture(80, 25)
  41. try:
  42. agent.set_size(-80, 70)
  43. except RuntimeError:
  44. pass