bpo-40275: Use new test.support helper submodules in tests (GH-21451)

This commit is contained in:
Hai Shi 2020-08-04 00:47:42 +08:00 committed by GitHub
parent a7f5d93bb6
commit bb0424b122
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 324 additions and 278 deletions

View file

@ -6,6 +6,8 @@ import unittest
import warnings
from unicodedata import normalize
from test import support
from test.support import os_helper
filenames = [
'1_abc',
@ -62,14 +64,14 @@ class UnicodeFileTests(unittest.TestCase):
def setUp(self):
try:
os.mkdir(support.TESTFN)
os.mkdir(os_helper.TESTFN)
except FileExistsError:
pass
self.addCleanup(support.rmtree, support.TESTFN)
self.addCleanup(os_helper.rmtree, os_helper.TESTFN)
files = set()
for name in self.files:
name = os.path.join(support.TESTFN, self.norm(name))
name = os.path.join(os_helper.TESTFN, self.norm(name))
with open(name, 'wb') as f:
f.write((name+'\n').encode("utf-8"))
os.stat(name)
@ -144,9 +146,10 @@ class UnicodeFileTests(unittest.TestCase):
sf0 = set(self.files)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
f1 = os.listdir(support.TESTFN.encode(sys.getfilesystemencoding()))
f2 = os.listdir(support.TESTFN)
sf2 = set(os.path.join(support.TESTFN, f) for f in f2)
f1 = os.listdir(os_helper.TESTFN.encode(
sys.getfilesystemencoding()))
f2 = os.listdir(os_helper.TESTFN)
sf2 = set(os.path.join(os_helper.TESTFN, f) for f in f2)
self.assertEqual(sf0, sf2, "%a != %a" % (sf0, sf2))
self.assertEqual(len(f1), len(f2))
@ -156,9 +159,10 @@ class UnicodeFileTests(unittest.TestCase):
os.rename("tmp", name)
def test_directory(self):
dirname = os.path.join(support.TESTFN, 'Gr\xfc\xdf-\u66e8\u66e9\u66eb')
dirname = os.path.join(os_helper.TESTFN,
'Gr\xfc\xdf-\u66e8\u66e9\u66eb')
filename = '\xdf-\u66e8\u66e9\u66eb'
with support.temp_cwd(dirname):
with os_helper.temp_cwd(dirname):
with open(filename, 'wb') as f:
f.write((filename + '\n').encode("utf-8"))
os.access(filename,os.R_OK)