diff options
author | Thomas Wouters <thomas@python.org> | 2001-03-22 14:50:24 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2001-03-22 14:50:24 (GMT) |
commit | b0dbeef1c4e455f5140a36a39c39b98c0f1c42c8 (patch) | |
tree | 231caa91da89f47efb7ddf1843da1fed8fba2ec5 /Lib/test/test_pty.py | |
parent | 053ae3502c19267f07c990d266e4cb3b2f3e01fc (diff) | |
download | cpython-b0dbeef1c4e455f5140a36a39c39b98c0f1c42c8.zip cpython-b0dbeef1c4e455f5140a36a39c39b98c0f1c42c8.tar.gz cpython-b0dbeef1c4e455f5140a36a39c39b98c0f1c42c8.tar.bz2 |
Allow the process of reading back what we wrote to a pty to transform
linefeeds into carriagereturn-linefeeds (which is apparently what IRIX
does.) Also add some comments, an extra test and reorganize it a bit.
Diffstat (limited to 'Lib/test/test_pty.py')
-rw-r--r-- | Lib/test/test_pty.py | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index 2a2d818..9b95754 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -1,10 +1,8 @@ import pty, os, sys from test_support import verbose, TestFailed, TestSkipped -TEST_STRING_1 = "I wish to buy a fish license." -TEST_STRING_2 = "For my pet fish, Eric." -TEST_STRING_3 = "And now for something completely different..." -TEST_STRING_4 = "but you pronounce it throatwobbler mangrove." +TEST_STRING_1 = "I wish to buy a fish license.\n" +TEST_STRING_2 = "For my pet fish, Eric.\n" if verbose: def debug(msg): @@ -30,13 +28,23 @@ except OSError: if not os.isatty(slave_fd): raise TestFailed, "slave_fd is not a tty" +# IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other +# differences (like extra whitespace, trailing garbage, etc.) + debug("Writing to slave_fd") -os.write(slave_fd, TEST_STRING_1) # should check return value -print os.read(master_fd, 1024) +os.write(slave_fd, TEST_STRING_1) +s1 = os.read(master_fd, 1024) +if s1[-2:] == "\r\n": + s1 = s1[:-2] + "\n" +sys.stdout.write(s1) +debug("Writing chunked output") os.write(slave_fd, TEST_STRING_2[:5]) os.write(slave_fd, TEST_STRING_2[5:]) -print os.read(master_fd, 1024) +s2 = os.read(master_fd, 1024) +if s2[-2:] == "\r\n": + s2 = s2[:-2] + "\n" +sys.stdout.write(s2) os.close(slave_fd) os.close(master_fd) @@ -46,26 +54,30 @@ os.close(master_fd) debug("calling pty.fork()") pid, master_fd = pty.fork() if pid == pty.CHILD: - ## # Please uncomment these when os.isatty() is added. - ## if not os.isatty(1): - ## debug("Child's fd 1 is not a tty?!") - ## os._exit(3) + # stdout should be connected to a tty. + if not os.isatty(1): + debug("Child's fd 1 is not a tty?!") + os._exit(3) + + # After pty.fork(), the child should already be a session leader. + # (on those systems that have that concept.) + debug("In child, calling os.setsid()") try: - debug("In child, calling os.setsid()") os.setsid() except OSError: # Good, we already were session leader - debug("OSError was raised.") + debug("Good: OSError was raised.") pass except AttributeError: # Have pty, but not setsid() ? - debug("AttributeError was raised.") + debug("No setsid() available ?") pass except: - # We don't want this error to propagate, escape the call to - # os._exit(), and cause very peculiar behavior in the calling + # We don't want this error to propagate, escaping the call to + # os._exit() and causing very peculiar behavior in the calling # regrtest.py ! - debug("Some other error was raised.") + # Note: could add traceback printing here. + debug("An unexpected error was raised.") os._exit(1) else: debug("os.setsid() succeeded! (bad!)") @@ -74,16 +86,16 @@ if pid == pty.CHILD: else: debug("Waiting for child (%d) to finish."%pid) (pid, status) = os.waitpid(pid, 0) - debug("Child (%d) exited with status %d."%(pid, status)) - if status / 256 == 1: + res = status / 256 + debug("Child (%d) exited with status %d (%d)."%(pid, res, status)) + if res == 1: raise TestFailed, "Child raised an unexpected exception in os.setsid()" - elif status / 256 == 2: + elif res == 2: raise TestFailed, "pty.fork() failed to make child a session leader." - elif status / 256 == 3: + elif res == 3: raise TestFailed, "Child spawned by pty.fork() did not have a tty as stdout" - elif status / 256 != 4: - raise TestFailed, "pty.fork() failed for unknown reasons:" - print os.read(master_fd, 65536) + elif res != 4: + raise TestFailed, "pty.fork() failed for unknown reasons." os.close(master_fd) |