mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-45162: Remove many old deprecated unittest features (GH-28268)
* "fail*" and "assert*" aliases of TestCase methods. * Broken from start TestCase method assertDictContainsSubset(). * Ignored TestLoader.loadTestsFromModule() parameter use_load_tests. * Old alias _TextTestResult of TextTestResult.
This commit is contained in:
parent
0361335b80
commit
b0a6ede3d0
14 changed files with 61 additions and 373 deletions
|
@ -696,36 +696,6 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
|
|||
self.assertRaises(self.failureException, self.assertNotIn, 'cow',
|
||||
animals)
|
||||
|
||||
def testAssertDictContainsSubset(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", DeprecationWarning)
|
||||
|
||||
self.assertDictContainsSubset({}, {})
|
||||
self.assertDictContainsSubset({}, {'a': 1})
|
||||
self.assertDictContainsSubset({'a': 1}, {'a': 1})
|
||||
self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2})
|
||||
self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2})
|
||||
|
||||
with self.assertRaises(self.failureException):
|
||||
self.assertDictContainsSubset({1: "one"}, {})
|
||||
|
||||
with self.assertRaises(self.failureException):
|
||||
self.assertDictContainsSubset({'a': 2}, {'a': 1})
|
||||
|
||||
with self.assertRaises(self.failureException):
|
||||
self.assertDictContainsSubset({'c': 1}, {'a': 1})
|
||||
|
||||
with self.assertRaises(self.failureException):
|
||||
self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
|
||||
|
||||
with self.assertRaises(self.failureException):
|
||||
self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
|
||||
|
||||
one = ''.join(chr(i) for i in range(255))
|
||||
# this used to cause a UnicodeDecodeError constructing the failure msg
|
||||
with self.assertRaises(self.failureException):
|
||||
self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'})
|
||||
|
||||
def testAssertEqual(self):
|
||||
equal_pairs = [
|
||||
((), ()),
|
||||
|
@ -1788,45 +1758,18 @@ test case
|
|||
pass
|
||||
self.assertIsNone(value)
|
||||
|
||||
def testDeprecatedMethodNames(self):
|
||||
"""
|
||||
Test that the deprecated methods raise a DeprecationWarning. See #9424.
|
||||
"""
|
||||
old = (
|
||||
(self.failIfEqual, (3, 5)),
|
||||
(self.assertNotEquals, (3, 5)),
|
||||
(self.failUnlessEqual, (3, 3)),
|
||||
(self.assertEquals, (3, 3)),
|
||||
(self.failUnlessAlmostEqual, (2.0, 2.0)),
|
||||
(self.assertAlmostEquals, (2.0, 2.0)),
|
||||
(self.failIfAlmostEqual, (3.0, 5.0)),
|
||||
(self.assertNotAlmostEquals, (3.0, 5.0)),
|
||||
(self.failUnless, (True,)),
|
||||
(self.assert_, (True,)),
|
||||
(self.failUnlessRaises, (TypeError, lambda _: 3.14 + 'spam')),
|
||||
(self.failIf, (False,)),
|
||||
(self.assertDictContainsSubset, (dict(a=1, b=2), dict(a=1, b=2, c=3))),
|
||||
(self.assertRaisesRegexp, (KeyError, 'foo', lambda: {}['foo'])),
|
||||
(self.assertRegexpMatches, ('bar', 'bar')),
|
||||
)
|
||||
for meth, args in old:
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
meth(*args)
|
||||
|
||||
# disable this test for now. When the version where the fail* methods will
|
||||
# be removed is decided, re-enable it and update the version
|
||||
def _testDeprecatedFailMethods(self):
|
||||
"""Test that the deprecated fail* methods get removed in 3.x"""
|
||||
if sys.version_info[:2] < (3, 3):
|
||||
return
|
||||
def testDeprecatedFailMethods(self):
|
||||
"""Test that the deprecated fail* methods get removed in 3.11"""
|
||||
deprecated_names = [
|
||||
'failIfEqual', 'failUnlessEqual', 'failUnlessAlmostEqual',
|
||||
'failIfAlmostEqual', 'failUnless', 'failUnlessRaises', 'failIf',
|
||||
'assertDictContainsSubset',
|
||||
'assertNotEquals', 'assertEquals', 'assertAlmostEquals',
|
||||
'assertNotAlmostEquals', 'assert_', 'assertDictContainsSubset',
|
||||
'assertRaisesRegexp', 'assertRegexpMatches'
|
||||
]
|
||||
for deprecated_name in deprecated_names:
|
||||
with self.assertRaises(AttributeError):
|
||||
getattr(self, deprecated_name) # remove these in 3.x
|
||||
getattr(self, deprecated_name)
|
||||
|
||||
def testDeepcopy(self):
|
||||
# Issue: 5660
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue