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

This commit is contained in:
Hai Shi 2020-07-06 17:15:08 +08:00 committed by GitHub
parent 883bc63833
commit a089d21df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 69 additions and 49 deletions

View file

@ -2,17 +2,18 @@
import unittest
import glob
import test.support
from test.support import import_helper
from test.support import os_helper
# Skip tests if dbm module doesn't exist.
dbm = test.support.import_module('dbm')
dbm = import_helper.import_module('dbm')
try:
from dbm import ndbm
except ImportError:
ndbm = None
_fname = test.support.TESTFN
_fname = os_helper.TESTFN
#
# Iterates over every database module supported by dbm currently available,
@ -34,7 +35,7 @@ def delete_files():
# we don't know the precise name the underlying database uses
# so we use glob to locate all names
for f in glob.glob(glob.escape(_fname) + "*"):
test.support.unlink(f)
os_helper.unlink(f)
class AnyDBMTestCase:
@ -74,7 +75,7 @@ class AnyDBMTestCase:
def test_anydbm_creation_n_file_exists_with_invalid_contents(self):
# create an empty file
test.support.create_empty_file(_fname)
os_helper.create_empty_file(_fname)
with dbm.open(_fname, 'n') as f:
self.assertEqual(len(f), 0)
@ -169,7 +170,7 @@ class WhichDBTestCase(unittest.TestCase):
# Issue 17198: check that ndbm which is referenced in whichdb is defined
db_file = '{}_ndbm.db'.format(_fname)
with open(db_file, 'w'):
self.addCleanup(test.support.unlink, db_file)
self.addCleanup(os_helper.unlink, db_file)
self.assertIsNone(self.dbm.whichdb(db_file[:-3]))
def tearDown(self):
@ -177,10 +178,10 @@ class WhichDBTestCase(unittest.TestCase):
def setUp(self):
delete_files()
self.filename = test.support.TESTFN
self.filename = os_helper.TESTFN
self.d = dbm.open(self.filename, 'c')
self.d.close()
self.dbm = test.support.import_fresh_module('dbm')
self.dbm = import_helper.import_fresh_module('dbm')
def test_keys(self):
self.d = dbm.open(self.filename, 'c')