[Python-checkins] cpython (merge 3.2 -> default): Closes #14158: merged test file resilience fix from 3.2.

vinay.sajip python-checkins at python.org
Fri Mar 2 02:24:21 CET 2012


http://hg.python.org/cpython/rev/a92e73dfbff6
changeset:   75364:a92e73dfbff6
parent:      75362:82032c64dd89
parent:      75363:707586c70195
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Fri Mar 02 01:24:13 2012 +0000
summary:
  Closes #14158: merged test file resilience fix from 3.2.

files:
  Lib/test/regrtest.py     |  23 +++++++++++++++++++----
  Lib/test/test_base64.py  |   5 +++++
  Lib/test/test_mailbox.py |  12 ++++++------
  3 files changed, 30 insertions(+), 10 deletions(-)


diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -749,10 +749,10 @@
         if bad:
             print(count(len(bad), "test"), "failed:")
             printlist(bad)
-        if environment_changed:
-            print("{} altered the execution environment:".format(
-                     count(len(environment_changed), "test")))
-            printlist(environment_changed)
+    if environment_changed:
+        print("{} altered the execution environment:".format(
+                 count(len(environment_changed), "test")))
+        printlist(environment_changed)
     if skipped and not quiet:
         print(count(len(skipped), "test"), "skipped:")
         printlist(skipped)
@@ -970,6 +970,7 @@
                  'multiprocessing.process._dangling',
                  'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES',
                  'packaging.command._COMMANDS', 'packaging.database_caches',
+                 'support.TESTFN',
                 )
 
     def get_sys_argv(self):
@@ -1163,6 +1164,20 @@
         sysconfig._SCHEMES._sections.clear()
         sysconfig._SCHEMES._sections.update(saved[2])
 
+    def get_support_TESTFN(self):
+        if os.path.isfile(support.TESTFN):
+            result = 'f'
+        elif os.path.isdir(support.TESTFN):
+            result = 'd'
+        else:
+            result = None
+        return result
+    def restore_support_TESTFN(self, saved_value):
+        if saved_value is None:
+            if os.path.isfile(support.TESTFN):
+                os.unlink(support.TESTFN)
+            elif os.path.isdir(support.TESTFN):
+                shutil.rmtree(support.TESTFN)
 
     def resource_info(self):
         for name in self.resources:
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -2,6 +2,7 @@
 from test import support
 import base64
 import binascii
+import os
 import sys
 import subprocess
 
@@ -274,6 +275,10 @@
 
 
 class TestMain(unittest.TestCase):
+    def tearDown(self):
+        if os.path.exists(support.TESTFN):
+            os.unlink(support.TESTFN)
+
     def get_output(self, *args, **options):
         args = (sys.executable, '-m', 'base64') + args
         return subprocess.check_output(args, **options)
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -7,6 +7,7 @@
 import email.message
 import re
 import io
+import shutil
 import tempfile
 from test import support
 import unittest
@@ -38,12 +39,7 @@
     def _delete_recursively(self, target):
         # Delete a file or delete a directory recursively
         if os.path.isdir(target):
-            for path, dirs, files in os.walk(target, topdown=False):
-                for name in files:
-                    os.remove(os.path.join(path, name))
-                for name in dirs:
-                    os.rmdir(os.path.join(path, name))
-            os.rmdir(target)
+            shutil.rmtree(target)
         elif os.path.exists(target):
             os.remove(target)
 
@@ -2028,6 +2024,10 @@
     def setUp(self):
         # create a new maildir mailbox to work with:
         self._dir = support.TESTFN
+        if os.path.isdir(self._dir):
+            shutil.rmtree(self._dir)
+        elif os.path.isfile(self._dir):
+            os.unlink(self._dir)
         os.mkdir(self._dir)
         os.mkdir(os.path.join(self._dir, "cur"))
         os.mkdir(os.path.join(self._dir, "tmp"))

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


More information about the Python-checkins mailing list