mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Closes #14158: merged test file resilience fix from 3.2.
This commit is contained in:
commit
2f24d98df0
3 changed files with 30 additions and 10 deletions
|
@ -970,6 +970,7 @@ class saved_test_environment:
|
||||||
'multiprocessing.process._dangling',
|
'multiprocessing.process._dangling',
|
||||||
'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES',
|
'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES',
|
||||||
'packaging.command._COMMANDS', 'packaging.database_caches',
|
'packaging.command._COMMANDS', 'packaging.database_caches',
|
||||||
|
'support.TESTFN',
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_sys_argv(self):
|
def get_sys_argv(self):
|
||||||
|
@ -1163,6 +1164,20 @@ class saved_test_environment:
|
||||||
sysconfig._SCHEMES._sections.clear()
|
sysconfig._SCHEMES._sections.clear()
|
||||||
sysconfig._SCHEMES._sections.update(saved[2])
|
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):
|
def resource_info(self):
|
||||||
for name in self.resources:
|
for name in self.resources:
|
||||||
|
|
|
@ -2,6 +2,7 @@ import unittest
|
||||||
from test import support
|
from test import support
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
@ -274,6 +275,10 @@ class BaseXYTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestMain(unittest.TestCase):
|
class TestMain(unittest.TestCase):
|
||||||
|
def tearDown(self):
|
||||||
|
if os.path.exists(support.TESTFN):
|
||||||
|
os.unlink(support.TESTFN)
|
||||||
|
|
||||||
def get_output(self, *args, **options):
|
def get_output(self, *args, **options):
|
||||||
args = (sys.executable, '-m', 'base64') + args
|
args = (sys.executable, '-m', 'base64') + args
|
||||||
return subprocess.check_output(args, **options)
|
return subprocess.check_output(args, **options)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import email
|
||||||
import email.message
|
import email.message
|
||||||
import re
|
import re
|
||||||
import io
|
import io
|
||||||
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
from test import support
|
from test import 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)
|
||||||
|
|
||||||
|
@ -2028,6 +2024,10 @@ class MaildirTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# create a new maildir mailbox to work with:
|
# create a new maildir mailbox to work with:
|
||||||
self._dir = support.TESTFN
|
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(self._dir)
|
||||||
os.mkdir(os.path.join(self._dir, "cur"))
|
os.mkdir(os.path.join(self._dir, "cur"))
|
||||||
os.mkdir(os.path.join(self._dir, "tmp"))
|
os.mkdir(os.path.join(self._dir, "tmp"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue