diff options
| author | Jeff Quast <contact@jeffquast.com> | 2015-09-22 12:42:24 -0700 |
|---|---|---|
| committer | Jeff Quast <contact@jeffquast.com> | 2015-09-22 12:42:24 -0700 |
| commit | 3c1bc018218b86177e1cdf8e93ead035afacc421 (patch) | |
| tree | 7c928ee4ad19c6c9610849f5f3b4bde7b5e8d4c4 /tests | |
| parent | ae480683db601dc162ab2d02643ff84e1c3786be (diff) | |
| parent | ea586fb9a545854f9b1212779653ec80f3428a2c (diff) | |
| download | pexpect-default-handle-sighup-pull.tar.gz | |
Merge remote-tracking branch 'origin/master' into default-handle-sighupdefault-handle-sighup-pull
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/sigwinch_report.py | 1 | ||||
| -rwxr-xr-x | tests/test_misc.py | 6 | ||||
| -rw-r--r-- | tests/test_unicode.py | 9 | ||||
| -rw-r--r-- | tests/test_which.py | 9 | ||||
| -rwxr-xr-x | tests/test_winsize.py | 59 |
5 files changed, 47 insertions, 37 deletions
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_misc.py b/tests/test_misc.py index d5a707c..16bdfc2 100755 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -317,9 +317,11 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase): " test forced self.__fork_pty() and __pty_make_controlling_tty " # given, class spawn_ourptyfork(pexpect.spawn): - def _spawn(self, command, args=[], preexec_fn=None): + def _spawn(self, command, args=[], preexec_fn=None, + dimensions=None): self.use_native_pty_fork = False - pexpect.spawn._spawn(self, command, args, preexec_fn) + pexpect.spawn._spawn(self, command, args, preexec_fn, + dimensions) # exercise, p = spawn_ourptyfork('cat', echo=False) diff --git a/tests/test_unicode.py b/tests/test_unicode.py index f342bf9..55632c3 100644 --- a/tests/test_unicode.py +++ b/tests/test_unicode.py @@ -173,6 +173,15 @@ class UnicodeTests(PexpectTestCase.PexpectTestCase): # exercise, assert child.readline() == 'input' + child.crlf + def test_unicode_argv(self): + """ Ensure a program can be executed with unicode arguments. """ + p = pexpect.spawn(u'echo ǝpoɔıun'.format(self=self), + timeout=5, encoding='utf8') + p.expect(u'ǝpoɔıun') + p.expect(pexpect.EOF) + assert not p.isalive() + assert p.exitstatus == 0 + if __name__ == '__main__': unittest.main() diff --git a/tests/test_which.py b/tests/test_which.py index bda3333..f909214 100644 --- a/tests/test_which.py +++ b/tests/test_which.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import subprocess import tempfile import shutil @@ -21,9 +22,13 @@ class TestCaseWhich(PexpectTestCase.PexpectTestCase): def test_os_defpath_which(self): " which() finds an executable in $PATH and returns its abspath. " - fname = 'cc' + bin_dir = tempfile.mkdtemp() - bin_path = os.path.join(bin_dir, fname) + temp_obj = tempfile.NamedTemporaryFile( + suffix=u'.sh', prefix=u'ǝpoɔıun-', + dir=bin_dir, delete=False) + bin_path = temp_obj.name + fname = os.path.basename(temp_obj.name) save_path = os.environ['PATH'] save_defpath = os.defpath diff --git a/tests/test_winsize.py b/tests/test_winsize.py index 75f8c0e..be16773 100755 --- a/tests/test_winsize.py +++ b/tests/test_winsize.py @@ -25,39 +25,32 @@ 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): + """ Assert initial window dimension size (24, 80). """ + 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): + """ Assert user-parameter window dimension size is initial. """ + 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): + """ Ensure method .setwinsize() sends signal caught by child. """ + 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() |
