Closes #14158: We now track test_support.TESTFN cleanup, and test_mailbox uses shutil.rmtree for simpler code.
This commit is contained in:
parent
1bf6bb6c37
commit
da563bfa48
|
@ -758,7 +758,9 @@ class saved_test_environment:
|
||||||
# the corresponding method names.
|
# the corresponding method names.
|
||||||
|
|
||||||
resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
|
resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
|
||||||
'os.environ', 'sys.path', 'asyncore.socket_map')
|
'os.environ', 'sys.path', 'asyncore.socket_map',
|
||||||
|
'test_support.TESTFN',
|
||||||
|
)
|
||||||
|
|
||||||
def get_sys_argv(self):
|
def get_sys_argv(self):
|
||||||
return id(sys.argv), sys.argv, sys.argv[:]
|
return id(sys.argv), sys.argv, sys.argv[:]
|
||||||
|
@ -809,6 +811,21 @@ class saved_test_environment:
|
||||||
asyncore.close_all(ignore_all=True)
|
asyncore.close_all(ignore_all=True)
|
||||||
asyncore.socket_map.update(saved_map)
|
asyncore.socket_map.update(saved_map)
|
||||||
|
|
||||||
|
def get_test_support_TESTFN(self):
|
||||||
|
if os.path.isfile(test_support.TESTFN):
|
||||||
|
result = 'f'
|
||||||
|
elif os.path.isdir(test_support.TESTFN):
|
||||||
|
result = 'd'
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
return result
|
||||||
|
def restore_test_support_TESTFN(self, saved_value):
|
||||||
|
if saved_value is None:
|
||||||
|
if os.path.isfile(test_support.TESTFN):
|
||||||
|
os.unlink(test_support.TESTFN)
|
||||||
|
elif os.path.isdir(test_support.TESTFN):
|
||||||
|
shutil.rmtree(test_support.TESTFN)
|
||||||
|
|
||||||
def resource_info(self):
|
def resource_info(self):
|
||||||
for name in self.resources:
|
for name in self.resources:
|
||||||
method_suffix = name.replace('.', '_')
|
method_suffix = name.replace('.', '_')
|
||||||
|
|
|
@ -6,6 +6,7 @@ import socket
|
||||||
import email
|
import email
|
||||||
import email.message
|
import email.message
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import StringIO
|
import StringIO
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -38,12 +39,7 @@ class TestBase(unittest.TestCase):
|
||||||
def _delete_recursively(self, target):
|
def _delete_recursively(self, target):
|
||||||
# Delete a file or delete a directory recursively
|
# Delete a file or delete a directory recursively
|
||||||
if os.path.isdir(target):
|
if os.path.isdir(target):
|
||||||
for path, dirs, files in os.walk(target, topdown=False):
|
shutil.rmtree(target)
|
||||||
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)
|
|
||||||
elif os.path.exists(target):
|
elif os.path.exists(target):
|
||||||
os.remove(target)
|
os.remove(target)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue