summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Quast <contact@jeffquast.com>2015-09-18 14:26:55 -0700
committerJeff Quast <contact@jeffquast.com>2015-09-18 14:26:55 -0700
commitd2bc99b668f5ecbe4be3f815f72db428ba13ff06 (patch)
tree9f0ed2c6f6144d74ac28843500008b0d96e19435
parente3f19f844ff72cd12b18c384a030323c635fc5d2 (diff)
downloadpexpect-d2bc99b668f5ecbe4be3f815f72db428ba13ff06.tar.gz
add changelog and tests for dimensions keyword arg
-rw-r--r--doc/history.rst3
-rwxr-xr-xtests/sigwinch_report.py1
-rwxr-xr-xtests/test_winsize.py56
3 files changed, 27 insertions, 33 deletions
diff --git a/doc/history.rst b/doc/history.rst
index 8186b47..863bf73 100644
--- a/doc/history.rst
+++ b/doc/history.rst
@@ -22,6 +22,9 @@ Version 4.0
* Removed the independent top-level modules (``pxssh fdpexpect FSM screen ANSI``)
which were installed alongside Pexpect. These were moved into the Pexpect
package in 3.0, but the old names were left as aliases.
+* New :class:`pexpect.spawn` keyword argument, ``dimensions=(rows, columns)``
+ allows setting terminal screen dimensions before launching a program
+ (:ghissue:`122`).
Version 3.4
```````````
diff --git a/tests/sigwinch_report.py b/tests/sigwinch_report.py
index 626d424..f10956a 100755
--- a/tests/sigwinch_report.py
+++ b/tests/sigwinch_report.py
@@ -39,6 +39,7 @@ def handler(signum, frame):
print('SIGWINCH:', getwinsize ())
sys.stdout.flush()
+print("Initial Size:", getwinsize())
print("setting handler for SIGWINCH")
signal.signal(signal.SIGWINCH, handler)
print("READY")
diff --git a/tests/test_winsize.py b/tests/test_winsize.py
index 75f8c0e..e7a71f2 100755
--- a/tests/test_winsize.py
+++ b/tests/test_winsize.py
@@ -25,39 +25,29 @@ import time
class TestCaseWinsize(PexpectTestCase.PexpectTestCase):
- def test_winsize (self):
- '''
- This tests that the child process can set and get the windows size.
- This makes use of an external script sigwinch_report.py.
- '''
- p1 = pexpect.spawn('%s sigwinch_report.py' % self.PYTHONBIN)
- p1.expect('READY', timeout=10)
-
- p1.setwinsize (11,22)
- index = p1.expect ([pexpect.TIMEOUT, b'SIGWINCH: \(([0-9]*), ([0-9]*)\)'],
- timeout=30)
- if index == 0:
- self.fail("TIMEOUT -- this platform may not support sigwinch properly.\n" + str(p1))
- self.assertEqual(p1.match.group(1, 2), (b"11" ,b"22"))
- self.assertEqual(p1.getwinsize(), (11, 22))
-
- time.sleep(1)
- p1.setwinsize (24,80)
- index = p1.expect ([pexpect.TIMEOUT, b'SIGWINCH: \(([0-9]*), ([0-9]*)\)'],
- timeout=10)
- if index == 0:
- self.fail ("TIMEOUT -- this platform may not support sigwinch properly.\n" + str(p1))
- self.assertEqual(p1.match.group(1, 2), (b"24" ,b"80"))
- self.assertEqual(p1.getwinsize(), (24, 80))
-
- p1.close()
-
-# def test_parent_resize (self):
-# pid = os.getpid()
-# p1 = pexpect.spawn('%s sigwinch_report.py' % self.PYTHONBIN)
-# time.sleep(10)
-# p1.setwinsize (11,22)
-# os.kill (pid, signal.SIGWINCH)
+ def test_initial_winsize(self):
+ p = pexpect.spawn('{self.PYTHONBIN} sigwinch_report.py'
+ .format(self=self), timeout=3)
+ # default size by PtyProcess class is 24 rows by 80 columns.
+ p.expect_exact('Initial Size: (24, 80)')
+ p.close()
+
+ def test_initial_winsize_by_dimension(self):
+ p = pexpect.spawn('{self.PYTHONBIN} sigwinch_report.py'
+ .format(self=self), timeout=3,
+ dimensions=(40, 100))
+ p.expect_exact('Initial Size: (40, 100)')
+ p.close()
+
+ def test_setwinsize(self):
+ p = pexpect.spawn('{self.PYTHONBIN} sigwinch_report.py'
+ .format(self=self), timeout=3)
+ # Note that we must await the installation of the child process'
+ # signal handler,
+ p.expect_exact('READY')
+ p.setwinsize(19, 84)
+ p.expect_exact('SIGWINCH: (19, 84)')
+ p.close()
if __name__ == '__main__':
unittest.main()