Imported Upstream version 12.1.0
[contrib/python-twisted.git] / twisted / test / process_tester.py
1 """Test program for processes."""
2
3 import sys, os
4
5 test_file_match = "process_test.log.*"
6 test_file = "process_test.log.%d" % os.getpid()
7
8 def main():
9     f = open(test_file, 'wb')
10     
11     # stage 1
12     bytes = sys.stdin.read(4)
13     f.write("one: %r\n" % bytes)
14     # stage 2
15     sys.stdout.write(bytes)
16     sys.stdout.flush()
17     os.close(sys.stdout.fileno())
18     
19     # and a one, and a two, and a...
20     bytes = sys.stdin.read(4)
21     f.write("two: %r\n" % bytes)
22     
23     # stage 3
24     sys.stderr.write(bytes)
25     sys.stderr.flush()
26     os.close(sys.stderr.fileno())
27     
28     # stage 4
29     bytes = sys.stdin.read(4)
30     f.write("three: %r\n" % bytes)
31
32     # exit with status code 23
33     sys.exit(23)
34
35
36 if __name__ == '__main__':
37     main()