summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2013-10-09 11:16:29 -0700
committerThomas Kluyver <takowl@gmail.com>2013-10-09 11:16:29 -0700
commit5ead18e1afe818fe6abfa7494c7d3655911626ec (patch)
tree8f465c1ae4de88d93b523a40c19ece1ee6159916
parent6c46341b69e98a523214478305916207e5c92414 (diff)
downloadpexpect-better-test-winsize.tar.gz
Improve test for setting and retrieving window sizebetter-test-winsize
-rw-r--r--pexpect/__init__.py2
-rwxr-xr-xtests/sigwinch_report.py1
-rwxr-xr-xtests/test_misc.py4
-rwxr-xr-xtests/test_winsize.py24
4 files changed, 15 insertions, 16 deletions
diff --git a/pexpect/__init__.py b/pexpect/__init__.py
index d23d8ab..6397a5f 100644
--- a/pexpect/__init__.py
+++ b/pexpect/__init__.py
@@ -1555,7 +1555,7 @@ class spawn(object):
TIOCGWINSZ = getattr(termios, 'TIOCGWINSZ', 1074295912)
s = struct.pack('HHHH', 0, 0, 0, 0)
- x = fcntl.ioctl(self.fileno(), TIOCGWINSZ, s)
+ x = fcntl.ioctl(self.child_fd, TIOCGWINSZ, s)
return struct.unpack('HHHH', x)[0:2]
def setwinsize(self, rows, cols):
diff --git a/tests/sigwinch_report.py b/tests/sigwinch_report.py
index d86d747..626d424 100755
--- a/tests/sigwinch_report.py
+++ b/tests/sigwinch_report.py
@@ -41,6 +41,7 @@ def handler(signum, frame):
print("setting handler for SIGWINCH")
signal.signal(signal.SIGWINCH, handler)
+print("READY")
while 1:
sys.stdout.flush()
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 00385ec..5c7f546 100755
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -219,10 +219,6 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
pass
else:
self.fail ("child.expect({}) should have raised a TypeError")
- def test_winsize(self):
- child = pexpect.spawn('cat')
- child.setwinsize(10,13)
- assert child.getwinsize()==(10,13), "getwinsize() did not return (10,13)"
def test_env(self):
default = pexpect.run('env')
diff --git a/tests/test_winsize.py b/tests/test_winsize.py
index 384e611..f029ad3 100755
--- a/tests/test_winsize.py
+++ b/tests/test_winsize.py
@@ -31,23 +31,25 @@ class TestCaseWinsize(PexpectTestCase.PexpectTestCase):
This makes use of an external script sigwinch_report.py.
'''
p1 = pexpect.spawn('%s sigwinch_report.py' % self.PYTHONBIN)
- time.sleep(10)
+ p1.expect('READY', timeout=10)
+
p1.setwinsize (11,22)
- time.sleep(3)
- index = p1.expect ([pexpect.TIMEOUT, b'SIGWINCH: \(([0-9]*), ([0-9]*)\)'], timeout=30)
+ 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))
- r = p1.match.group(1)
- c = p1.match.group(2)
- assert (r==b"11" and c==b"22")
+ 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)
+ 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))
- r = p1.match.group(1)
- c = p1.match.group(2)
- assert (r==b"24" and c==b"80")
+ self.assertEqual(p1.match.group(1, 2), (b"24" ,b"80"))
+ self.assertEqual(p1.getwinsize(), (24, 80))
+
p1.close()
# def test_parent_resize (self):