~ubuntu-branches/ubuntu/precise/python3.2/precise-proposed

« back to all changes in this revision

Viewing changes to Lib/test/test_tempfile.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 18:40:39 UTC
  • mfrom: (30.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120309184039-j3yk2emxr1plyo21
Tags: 3.2.3~rc1-1
* Python 3.2.3 release candidate 1.
* Update to 20120309 from the 3.2 branch.
* Fix libpython.a symlink. Closes: #660146.
* Build-depend on xauth.
* Run the gdb tests for the debug build only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# tempfile.py unit tests.
2
2
import tempfile
3
3
import os
 
4
import signal
4
5
import sys
5
6
import re
6
7
import warnings
135
136
        except:
136
137
            self.failOnException("iteration")
137
138
 
 
139
    @unittest.skipUnless(hasattr(os, 'fork'),
 
140
        "os.fork is required for this test")
 
141
    def test_process_awareness(self):
 
142
        # ensure that the random source differs between
 
143
        # child and parent.
 
144
        read_fd, write_fd = os.pipe()
 
145
        pid = None
 
146
        try:
 
147
            pid = os.fork()
 
148
            if not pid:
 
149
                os.close(read_fd)
 
150
                os.write(write_fd, next(self.r).encode("ascii"))
 
151
                os.close(write_fd)
 
152
                # bypass the normal exit handlers- leave those to
 
153
                # the parent.
 
154
                os._exit(0)
 
155
            parent_value = next(self.r)
 
156
            child_value = os.read(read_fd, len(parent_value)).decode("ascii")
 
157
        finally:
 
158
            if pid:
 
159
                # best effort to ensure the process can't bleed out
 
160
                # via any bugs above
 
161
                try:
 
162
                    os.kill(pid, signal.SIGKILL)
 
163
                except EnvironmentError:
 
164
                    pass
 
165
            os.close(read_fd)
 
166
            os.close(write_fd)
 
167
        self.assertNotEqual(child_value, parent_value)
 
168
 
 
169
 
138
170
test_classes.append(test__RandomNameSequence)
139
171
 
140
172