From 8ebe27f30012ad1858edf41a0ee0be16ff70127b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 21 Dec 2010 19:24:26 +0000 Subject: Deprecate assertDictContainsSubset() --- Doc/library/unittest.rst | 9 ++++++--- Lib/unittest/case.py | 2 ++ Lib/unittest/test/test_case.py | 3 ++- Misc/NEWS | 12 ++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index 9d0d90a..9c0f1a1 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1078,9 +1078,6 @@ Test cases | :meth:`assertNotRegex(s, re) | ``not regex.search(s)`` | 3.2 | | ` | | | +---------------------------------------+--------------------------------+--------------+ - | :meth:`assertDictContainsSubset(a, b) | all the key/value pairs | 3.1 | - | ` | in `a` exist in `b` | | - +---------------------------------------+--------------------------------+--------------+ | :meth:`assertCountEqual(a, b) | `a` and `b` have the same | 3.2 | | ` | elements in the same number, | | | | regardless of their order | | @@ -1145,7 +1142,13 @@ Test cases those in *subset*. If not, an error message listing the missing keys and mismatched values is generated. + Note, the arguments are in the opposite order of what the method name + dictates. Instead, consider using the set-methods on :ref:`dictionary + views `, for example: ``d.keys() <= e.keys()`` or + ``d.items() <= d.items()``. + .. versionadded:: 3.1 + .. deprecated:: 3.2 .. method:: assertCountEqual(actual, expected, msg=None) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index b02d475..15c7eee 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -934,6 +934,8 @@ class TestCase(object): def assertDictContainsSubset(self, subset, dictionary, msg=None): """Checks whether dictionary is a superset of subset.""" + warnings.warn('assertDictContainsSubset is deprecated', + DeprecationWarning) missing = [] mismatched = [] for key, value in subset.items(): diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 3ad883d..3376428 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -1079,6 +1079,7 @@ test case (self.failUnlessRaises, (TypeError, lambda _: 3.14 + 'spam')), (self.failIf, (False,)), (self.assertSameElements, ([1, 1, 2, 3], [1, 2, 3])), + (self.assertDictContainsSubset, (dict(a=1, b=2), dict(a=1, b=2, c=3))), (self.assertRaisesRegexp, (KeyError, 'foo', lambda: {}['foo'])), (self.assertRegexpMatches, ('bar', 'bar')), ) @@ -1093,7 +1094,7 @@ test case deprecated_names = [ 'failIfEqual', 'failUnlessEqual', 'failUnlessAlmostEqual', 'failIfAlmostEqual', 'failUnless', 'failUnlessRaises', 'failIf', - 'assertSameElements' + 'assertSameElements', 'assertDictContainsSubset', ] for deprecated_name in deprecated_names: with self.assertRaises(AttributeError): diff --git a/Misc/NEWS b/Misc/NEWS index 1a49d3e..ea4e52d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2,6 +2,18 @@ Python News +++++++++++ +What's New in Python 3.2 Release Candidate 1 +============================================ + +Core and Builtins +----------------- + +Library +------- + +- Deprecated assertDictContainsSubclass() in the unittest module. + + What's New in Python 3.2 Beta 2? ================================ -- cgit v0.12