2 from test
.test_support
import verbose
, TestFailed
, TestSkipped
4 TEST_STRING_1
= "I wish to buy a fish license.\n"
5 TEST_STRING_2
= "For my pet fish, Eric.\n"
14 # Marginal testing of pty suite. Cannot do extensive 'do or fail' testing
15 # because pty code is not too portable.
18 debug("Calling master_open()")
19 master_fd
, slave_name
= pty
.master_open()
20 debug("Got master_fd '%d', slave_name '%s'"%(master_fd
, slave_name
))
21 debug("Calling slave_open(%s)"%`slave_name`
)
22 slave_fd
= pty
.slave_open(slave_name
)
23 debug("Got slave_fd '%d'"%slave
_fd
)
25 # " An optional feature could not be imported " ... ?
26 raise TestSkipped
, "Pseudo-terminals (seemingly) not functional."
28 if not os
.isatty(slave_fd
):
29 raise TestFailed
, "slave_fd is not a tty"
31 # IRIX apparently turns \n into \r\n. Allow that, but avoid allowing other
32 # differences (like extra whitespace, trailing garbage, etc.)
34 debug("Writing to slave_fd")
35 os
.write(slave_fd
, TEST_STRING_1
)
36 s1
= os
.read(master_fd
, 1024)
37 sys
.stdout
.write(s1
.replace("\r\n", "\n"))
39 debug("Writing chunked output")
40 os
.write(slave_fd
, TEST_STRING_2
[:5])
41 os
.write(slave_fd
, TEST_STRING_2
[5:])
42 s2
= os
.read(master_fd
, 1024)
43 sys
.stdout
.write(s2
.replace("\r\n", "\n"))
50 debug("calling pty.fork()")
51 pid
, master_fd
= pty
.fork()
53 # stdout should be connected to a tty.
55 debug("Child's fd 1 is not a tty?!")
58 # After pty.fork(), the child should already be a session leader.
59 # (on those systems that have that concept.)
60 debug("In child, calling os.setsid()")
64 # Good, we already were session leader
65 debug("Good: OSError was raised.")
67 except AttributeError:
68 # Have pty, but not setsid() ?
69 debug("No setsid() available ?")
72 # We don't want this error to propagate, escaping the call to
73 # os._exit() and causing very peculiar behavior in the calling
75 # Note: could add traceback printing here.
76 debug("An unexpected error was raised.")
79 debug("os.setsid() succeeded! (bad!)")
83 debug("Waiting for child (%d) to finish."%pid
)
84 (pid
, status
) = os
.waitpid(pid
, 0)
86 debug("Child (%d) exited with status %d (%d)."%(pid
, res
, status
))
88 raise TestFailed
, "Child raised an unexpected exception in os.setsid()"
90 raise TestFailed
, "pty.fork() failed to make child a session leader."
92 raise TestFailed
, "Child spawned by pty.fork() did not have a tty as stdout"
94 raise TestFailed
, "pty.fork() failed for unknown reasons."