bpo-40275: Use new test.support helper submodules in tests (GH-21772)
This commit is contained in:
parent
e27a51c11e
commit
fcce8c649a
|
@ -25,7 +25,7 @@ import threading
|
||||||
import unittest
|
import unittest
|
||||||
import sqlite3 as sqlite
|
import sqlite3 as sqlite
|
||||||
|
|
||||||
from test.support import TESTFN, unlink
|
from test.support.os_helper import TESTFN, unlink
|
||||||
|
|
||||||
|
|
||||||
class ModuleTests(unittest.TestCase):
|
class ModuleTests(unittest.TestCase):
|
||||||
|
|
|
@ -4,6 +4,8 @@ import sys
|
||||||
import warnings
|
import warnings
|
||||||
from inspect import isabstract
|
from inspect import isabstract
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import os_helper
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from _abc import _get_dump
|
from _abc import _get_dump
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -61,7 +63,7 @@ def dash_R(ns, test_name, test_func):
|
||||||
return int_pool.setdefault(value, value)
|
return int_pool.setdefault(value, value)
|
||||||
|
|
||||||
nwarmup, ntracked, fname = ns.huntrleaks
|
nwarmup, ntracked, fname = ns.huntrleaks
|
||||||
fname = os.path.join(support.SAVEDCWD, fname)
|
fname = os.path.join(os_helper.SAVEDCWD, fname)
|
||||||
repcount = nwarmup + ntracked
|
repcount = nwarmup + ntracked
|
||||||
|
|
||||||
# Pre-allocate to ensure that the loop doesn't allocate anything new
|
# Pre-allocate to ensure that the loop doesn't allocate anything new
|
||||||
|
@ -71,7 +73,7 @@ def dash_R(ns, test_name, test_func):
|
||||||
fd_deltas = [0] * repcount
|
fd_deltas = [0] * repcount
|
||||||
getallocatedblocks = sys.getallocatedblocks
|
getallocatedblocks = sys.getallocatedblocks
|
||||||
gettotalrefcount = sys.gettotalrefcount
|
gettotalrefcount = sys.gettotalrefcount
|
||||||
fd_count = support.fd_count
|
fd_count = os_helper.fd_count
|
||||||
|
|
||||||
# initialize variables to make pyflakes quiet
|
# initialize variables to make pyflakes quiet
|
||||||
rc_before = alloc_before = fd_before = 0
|
rc_before = alloc_before = fd_before = 0
|
||||||
|
|
|
@ -5,7 +5,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import uuid
|
import uuid
|
||||||
import winreg
|
import winreg
|
||||||
from test import support
|
from test.support import os_helper
|
||||||
from test.libregrtest.utils import print_warning
|
from test.libregrtest.utils import print_warning
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +69,9 @@ class WindowsLoadTracker():
|
||||||
# Spawn off the load monitor
|
# Spawn off the load monitor
|
||||||
counter_name = self._get_counter_name()
|
counter_name = self._get_counter_name()
|
||||||
command = ['typeperf', counter_name, '-si', str(SAMPLING_INTERVAL)]
|
command = ['typeperf', counter_name, '-si', str(SAMPLING_INTERVAL)]
|
||||||
self._popen = subprocess.Popen(' '.join(command), stdout=command_stdout, cwd=support.SAVEDCWD)
|
self._popen = subprocess.Popen(' '.join(command),
|
||||||
|
stdout=command_stdout,
|
||||||
|
cwd=os_helper.SAVEDCWD)
|
||||||
|
|
||||||
# Close our copy of the write end of the pipe
|
# Close our copy of the write end of the pipe
|
||||||
os.close(command_stdout)
|
os.close(command_stdout)
|
||||||
|
|
|
@ -5,6 +5,9 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import import_helper
|
||||||
|
from test.support import os_helper
|
||||||
|
|
||||||
|
|
||||||
if not hasattr(sys, "addaudithook") or not hasattr(sys, "audit"):
|
if not hasattr(sys, "addaudithook") or not hasattr(sys, "audit"):
|
||||||
raise unittest.SkipTest("test only relevant when sys.audit is available")
|
raise unittest.SkipTest("test only relevant when sys.audit is available")
|
||||||
|
@ -52,7 +55,7 @@ class AuditTest(unittest.TestCase):
|
||||||
self.do_test("test_block_add_hook_baseexception")
|
self.do_test("test_block_add_hook_baseexception")
|
||||||
|
|
||||||
def test_pickle(self):
|
def test_pickle(self):
|
||||||
support.import_module("pickle")
|
import_helper.import_module("pickle")
|
||||||
|
|
||||||
self.do_test("test_pickle")
|
self.do_test("test_pickle")
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ class AuditTest(unittest.TestCase):
|
||||||
self.do_test("test_monkeypatch")
|
self.do_test("test_monkeypatch")
|
||||||
|
|
||||||
def test_open(self):
|
def test_open(self):
|
||||||
self.do_test("test_open", support.TESTFN)
|
self.do_test("test_open", os_helper.TESTFN)
|
||||||
|
|
||||||
def test_cantrace(self):
|
def test_cantrace(self):
|
||||||
self.do_test("test_cantrace")
|
self.do_test("test_cantrace")
|
||||||
|
@ -89,7 +92,7 @@ class AuditTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_winreg(self):
|
def test_winreg(self):
|
||||||
support.import_module("winreg")
|
import_helper.import_module("winreg")
|
||||||
returncode, events, stderr = self.run_python("test_winreg")
|
returncode, events, stderr = self.run_python("test_winreg")
|
||||||
if returncode:
|
if returncode:
|
||||||
self.fail(stderr)
|
self.fail(stderr)
|
||||||
|
@ -103,7 +106,7 @@ class AuditTest(unittest.TestCase):
|
||||||
self.assertSequenceEqual(["winreg.PyHKEY.Detach", " ", expected], events[4])
|
self.assertSequenceEqual(["winreg.PyHKEY.Detach", " ", expected], events[4])
|
||||||
|
|
||||||
def test_socket(self):
|
def test_socket(self):
|
||||||
support.import_module("socket")
|
import_helper.import_module("socket")
|
||||||
returncode, events, stderr = self.run_python("test_socket")
|
returncode, events, stderr = self.run_python("test_socket")
|
||||||
if returncode:
|
if returncode:
|
||||||
self.fail(stderr)
|
self.fail(stderr)
|
||||||
|
|
|
@ -17,6 +17,7 @@ import unittest
|
||||||
|
|
||||||
import test.support
|
import test.support
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
|
from test.support import warnings_helper
|
||||||
import test.string_tests
|
import test.string_tests
|
||||||
import test.list_tests
|
import test.list_tests
|
||||||
from test.support import bigaddrspacetest, MAX_Py_ssize_t
|
from test.support import bigaddrspacetest, MAX_Py_ssize_t
|
||||||
|
@ -27,7 +28,7 @@ if sys.flags.bytes_warning:
|
||||||
def check_bytes_warnings(func):
|
def check_bytes_warnings(func):
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kw):
|
def wrapper(*args, **kw):
|
||||||
with test.support.check_warnings(('', BytesWarning)):
|
with warnings_helper.check_warnings(('', BytesWarning)):
|
||||||
return func(*args, **kw)
|
return func(*args, **kw)
|
||||||
return wrapper
|
return wrapper
|
||||||
else:
|
else:
|
||||||
|
@ -1769,7 +1770,7 @@ class AssortedBytesTest(unittest.TestCase):
|
||||||
"BytesWarning is needed for this test: use -bb option")
|
"BytesWarning is needed for this test: use -bb option")
|
||||||
def test_compare(self):
|
def test_compare(self):
|
||||||
def bytes_warning():
|
def bytes_warning():
|
||||||
return test.support.check_warnings(('', BytesWarning))
|
return warnings_helper.check_warnings(('', BytesWarning))
|
||||||
with bytes_warning():
|
with bytes_warning():
|
||||||
b'' == ''
|
b'' == ''
|
||||||
with bytes_warning():
|
with bytes_warning():
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
|
from test.support import os_helper
|
||||||
import_helper.import_module("dbm.ndbm") #skip if not supported
|
import_helper.import_module("dbm.ndbm") #skip if not supported
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -9,7 +10,7 @@ from dbm.ndbm import error
|
||||||
class DbmTestCase(unittest.TestCase):
|
class DbmTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.filename = support.TESTFN
|
self.filename = os_helper.TESTFN
|
||||||
self.d = dbm.ndbm.open(self.filename, 'c')
|
self.d = dbm.ndbm.open(self.filename, 'c')
|
||||||
self.d.close()
|
self.d.close()
|
||||||
|
|
||||||
|
@ -102,10 +103,10 @@ class DbmTestCase(unittest.TestCase):
|
||||||
with self.assertRaises(error):
|
with self.assertRaises(error):
|
||||||
db[b'not exist key'] = b'not exist value'
|
db[b'not exist key'] = b'not exist value'
|
||||||
|
|
||||||
@unittest.skipUnless(support.TESTFN_NONASCII,
|
@unittest.skipUnless(os_helper.TESTFN_NONASCII,
|
||||||
'requires OS support of non-ASCII encodings')
|
'requires OS support of non-ASCII encodings')
|
||||||
def test_nonascii_filename(self):
|
def test_nonascii_filename(self):
|
||||||
filename = support.TESTFN_NONASCII
|
filename = os_helper.TESTFN_NONASCII
|
||||||
for suffix in ['', '.pag', '.dir', '.db']:
|
for suffix in ['', '.pag', '.dir', '.db']:
|
||||||
self.addCleanup(support.unlink, filename + suffix)
|
self.addCleanup(support.unlink, filename + suffix)
|
||||||
with dbm.ndbm.open(filename, 'c') as db:
|
with dbm.ndbm.open(filename, 'c') as db:
|
||||||
|
|
|
@ -2975,12 +2975,12 @@ order (MRO) for bases """
|
||||||
## self.ateof = 1
|
## self.ateof = 1
|
||||||
## return s
|
## return s
|
||||||
##
|
##
|
||||||
## f = file(name=support.TESTFN, mode='w')
|
## f = file(name=os_helper.TESTFN, mode='w')
|
||||||
## lines = ['a\n', 'b\n', 'c\n']
|
## lines = ['a\n', 'b\n', 'c\n']
|
||||||
## try:
|
## try:
|
||||||
## f.writelines(lines)
|
## f.writelines(lines)
|
||||||
## f.close()
|
## f.close()
|
||||||
## f = CountedInput(support.TESTFN)
|
## f = CountedInput(os_helper.TESTFN)
|
||||||
## for (i, expected) in zip(range(1, 5) + [4], lines + 2 * [""]):
|
## for (i, expected) in zip(range(1, 5) + [4], lines + 2 * [""]):
|
||||||
## got = f.readline()
|
## got = f.readline()
|
||||||
## self.assertEqual(expected, got)
|
## self.assertEqual(expected, got)
|
||||||
|
@ -2992,7 +2992,7 @@ order (MRO) for bases """
|
||||||
## f.close()
|
## f.close()
|
||||||
## except:
|
## except:
|
||||||
## pass
|
## pass
|
||||||
## support.unlink(support.TESTFN)
|
## os_helper.unlink(os_helper.TESTFN)
|
||||||
|
|
||||||
def test_keywords(self):
|
def test_keywords(self):
|
||||||
# Testing keyword args to basic type constructors ...
|
# Testing keyword args to basic type constructors ...
|
||||||
|
|
|
@ -111,7 +111,7 @@ EXTERNAL_ENTITY_XML = """\
|
||||||
def checkwarnings(*filters, quiet=False):
|
def checkwarnings(*filters, quiet=False):
|
||||||
def decorator(test):
|
def decorator(test):
|
||||||
def newtest(*args, **kwargs):
|
def newtest(*args, **kwargs):
|
||||||
with support.check_warnings(*filters, quiet=quiet):
|
with warnings_helper.check_warnings(*filters, quiet=quiet):
|
||||||
test(*args, **kwargs)
|
test(*args, **kwargs)
|
||||||
functools.update_wrapper(newtest, test)
|
functools.update_wrapper(newtest, test)
|
||||||
return newtest
|
return newtest
|
||||||
|
|
Loading…
Reference in New Issue