Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_wait3.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 228cfb6e2900 |
| children |
| rev | line source |
|---|---|
|
37099
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
1 """This test checks for correct wait3() behavior. |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
2 """ |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
3 |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
4 import os |
| 39032 | 5 import time |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
6 import unittest |
|
37099
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
7 from test.fork_wait import ForkWait |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
8 from test.test_support import run_unittest, reap_children |
|
37099
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
9 |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
10 try: |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
11 os.fork |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
12 except AttributeError: |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
13 raise unittest.SkipTest, "os.fork not defined -- skipping test_wait3" |
|
37099
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
14 |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
15 try: |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
16 os.wait3 |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
17 except AttributeError: |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
18 raise unittest.SkipTest, "os.wait3 not defined -- skipping test_wait3" |
|
37099
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
19 |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
20 class Wait3Test(ForkWait): |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
21 def wait_impl(self, cpid): |
| 39032 | 22 for i in range(10): |
| 23 # wait3() shouldn't hang, but some of the buildbots seem to hang | |
| 24 # in the forking tests. This is an attempt to fix the problem. | |
| 25 spid, status, rusage = os.wait3(os.WNOHANG) | |
| 37104 | 26 if spid == cpid: |
| 27 break | |
| 39032 | 28 time.sleep(1.0) |
| 29 | |
|
37099
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
30 self.assertEqual(spid, cpid) |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
31 self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
32 self.assertTrue(rusage) |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
33 |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
34 def test_main(): |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
35 run_unittest(Wait3Test) |
|
38961
0a83dc3529d1
Add new utility function, reap_children(), to test_support. This should
Neal Norwitz <nnorwitz@gmail.com>
parents:
38869
diff
changeset
|
36 reap_children() |
|
37099
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
37 |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
38 if __name__ == "__main__": |
|
d62b13488943
Patch #1309579: wait3 and wait4 were added to the posix module by Chad J. Schroeder.
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff
changeset
|
39 test_main() |
