[Python-checkins] cpython (3.2): Fix ProcessTestCasePOSIXPurePython to test the module from import when

gregory.p.smith python-checkins at python.org
Sat May 28 18:13:58 CEST 2011


http://hg.python.org/cpython/rev/4f248dd34dd9
changeset:   70465:4f248dd34dd9
branch:      3.2
parent:      70463:7f2e3c466d57
user:        Gregory P. Smith <greg at krypto.org>
date:        Sat May 28 09:06:02 2011 -0700
summary:
  Fix ProcessTestCasePOSIXPurePython to test the module from import when
_posixsubprocess doesn't exist rather than simply stubbing it out
after the fact.  This adds coverage for the RuntimeWarning as well as
using the pure python _create_pipe instead of using
_posixsubprocess.cloexec_pipe unintentionally with the pure python
code.

Ironically: I don't think any platform should ever actually _use_ the
pure Python subprocess code on POSIX platforms anymore.  This at least
tests it properly in this stable branch.  The pure python code for
this is likely to be removed in 3.3.

files:
  Lib/test/test_subprocess.py |  24 ++++++++++++++++--------
  1 files changed, 16 insertions(+), 8 deletions(-)


diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1399,15 +1399,23 @@
 @unittest.skipUnless(getattr(subprocess, '_posixsubprocess', False),
                      "_posixsubprocess extension module not found.")
 class ProcessTestCasePOSIXPurePython(ProcessTestCase, POSIXProcessTestCase):
-    def setUp(self):
-        subprocess._posixsubprocess = None
-        ProcessTestCase.setUp(self)
-        POSIXProcessTestCase.setUp(self)
+    @classmethod
+    def setUpClass(cls):
+        global subprocess
+        assert subprocess._posixsubprocess
+        # Reimport subprocess while forcing _posixsubprocess to not exist.
+        with support.check_warnings(('.*_posixsubprocess .* not being used.*',
+                                     RuntimeWarning)):
+            subprocess = support.import_fresh_module(
+                    'subprocess', blocked=['_posixsubprocess'])
+        assert not subprocess._posixsubprocess
 
-    def tearDown(self):
-        subprocess._posixsubprocess = sys.modules['_posixsubprocess']
-        POSIXProcessTestCase.tearDown(self)
-        ProcessTestCase.tearDown(self)
+    @classmethod
+    def tearDownClass(cls):
+        global subprocess
+        # Reimport subprocess as it should be, restoring order to the universe.
+        subprocess = support.import_fresh_module('subprocess')
+        assert subprocess._posixsubprocess
 
 
 class HelperFunctionTests(unittest.TestCase):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list