[Python-checkins] r88451 - in python/branches/py3k/Lib/unittest: case.py test/_test_warnings.py test/test_assertions.py test/test_case.py test/test_runner.py

georg.brandl python-checkins at python.org
Sun Feb 20 12:18:09 CET 2011


Author: georg.brandl
Date: Sun Feb 20 12:18:09 2011
New Revision: 88451

Log:
Remove unittest methods scheduled for removal in 3.3 -- makes the unittest test suite pass again.

Modified:
   python/branches/py3k/Lib/unittest/case.py
   python/branches/py3k/Lib/unittest/test/_test_warnings.py
   python/branches/py3k/Lib/unittest/test/test_assertions.py
   python/branches/py3k/Lib/unittest/test/test_case.py
   python/branches/py3k/Lib/unittest/test/test_runner.py

Modified: python/branches/py3k/Lib/unittest/case.py
==============================================================================
--- python/branches/py3k/Lib/unittest/case.py	(original)
+++ python/branches/py3k/Lib/unittest/case.py	Sun Feb 20 12:18:09 2011
@@ -938,77 +938,6 @@
             standardMsg = self._truncateMessage(standardMsg, diff)
             self.fail(self._formatMessage(msg, standardMsg))
 
-    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():
-            if key not in dictionary:
-                missing.append(key)
-            elif value != dictionary[key]:
-                mismatched.append('%s, expected: %s, actual: %s' %
-                                  (safe_repr(key), safe_repr(value),
-                                   safe_repr(dictionary[key])))
-
-        if not (missing or mismatched):
-            return
-
-        standardMsg = ''
-        if missing:
-            standardMsg = 'Missing: %s' % ','.join(safe_repr(m) for m in
-                                                    missing)
-        if mismatched:
-            if standardMsg:
-                standardMsg += '; '
-            standardMsg += 'Mismatched values: %s' % ','.join(mismatched)
-
-        self.fail(self._formatMessage(msg, standardMsg))
-
-    def assertSameElements(self, expected_seq, actual_seq, msg=None):
-        """An unordered sequence specific comparison.
-
-        Raises with an error message listing which elements of expected_seq
-        are missing from actual_seq and vice versa if any.
-
-        Duplicate elements are ignored when comparing *expected_seq* and
-        *actual_seq*. It is the equivalent of ``assertEqual(set(expected),
-        set(actual))`` but it works with sequences of unhashable objects as
-        well.
-        """
-        warnings.warn('assertSameElements is deprecated',
-                      DeprecationWarning)
-        try:
-            expected = set(expected_seq)
-            actual = set(actual_seq)
-            missing = sorted(expected.difference(actual))
-            unexpected = sorted(actual.difference(expected))
-        except TypeError:
-            # Fall back to slower list-compare if any of the objects are
-            # not hashable.
-            expected = list(expected_seq)
-            actual = list(actual_seq)
-            try:
-                expected.sort()
-                actual.sort()
-            except TypeError:
-                missing, unexpected = unorderable_list_difference(expected,
-                                                                  actual)
-            else:
-                missing, unexpected = sorted_list_difference(expected, actual)
-        errors = []
-        if missing:
-            errors.append('Expected, but missing:\n    %s' %
-                          safe_repr(missing))
-        if unexpected:
-            errors.append('Unexpected, but present:\n    %s' %
-                          safe_repr(unexpected))
-        if errors:
-            standardMsg = '\n'.join(errors)
-            self.fail(self._formatMessage(msg, standardMsg))
-
-
     def assertCountEqual(self, first, second, msg=None):
         """An unordered sequence comparison asserting that the same elements,
         regardless of order.  If the same element occurs more than once,
@@ -1183,13 +1112,11 @@
 
     # The fail* methods can be removed in 3.3, the 5 assert* methods will
     # have to stay around for a few more versions.  See #9424.
-    failUnlessEqual = assertEquals = _deprecate(assertEqual)
-    failIfEqual = assertNotEquals = _deprecate(assertNotEqual)
-    failUnlessAlmostEqual = assertAlmostEquals = _deprecate(assertAlmostEqual)
-    failIfAlmostEqual = assertNotAlmostEquals = _deprecate(assertNotAlmostEqual)
-    failUnless = assert_ = _deprecate(assertTrue)
-    failUnlessRaises = _deprecate(assertRaises)
-    failIf = _deprecate(assertFalse)
+    assertEquals = _deprecate(assertEqual)
+    assertNotEquals = _deprecate(assertNotEqual)
+    assertAlmostEquals = _deprecate(assertAlmostEqual)
+    assertNotAlmostEquals = _deprecate(assertNotAlmostEqual)
+    assert_ = _deprecate(assertTrue)
     assertRaisesRegexp = _deprecate(assertRaisesRegex)
     assertRegexpMatches = _deprecate(assertRegex)
 

Modified: python/branches/py3k/Lib/unittest/test/_test_warnings.py
==============================================================================
--- python/branches/py3k/Lib/unittest/test/_test_warnings.py	(original)
+++ python/branches/py3k/Lib/unittest/test/_test_warnings.py	Sun Feb 20 12:18:09 2011
@@ -19,17 +19,12 @@
     warnings.warn('rw', RuntimeWarning)
 
 class TestWarnings(unittest.TestCase):
-    # unittest warnings will be printed at most once per type (max one message
-    # for the fail* methods, and one for the assert* methods)
+    # unittest warnings will be printed at most once per type
     def test_assert(self):
         self.assertEquals(2+2, 4)
         self.assertEquals(2*2, 4)
         self.assertEquals(2**2, 4)
 
-    def test_fail(self):
-        self.failUnless(1)
-        self.failUnless(True)
-
     def test_other_unittest(self):
         self.assertAlmostEqual(2+2, 4)
         self.assertNotAlmostEqual(4+4, 2)

Modified: python/branches/py3k/Lib/unittest/test/test_assertions.py
==============================================================================
--- python/branches/py3k/Lib/unittest/test/test_assertions.py	(original)
+++ python/branches/py3k/Lib/unittest/test/test_assertions.py	Sun Feb 20 12:18:09 2011
@@ -223,15 +223,6 @@
                              "\+ \{'key': 'value'\}$",
                              "\+ \{'key': 'value'\} : oops$"])
 
-    def testAssertDictContainsSubset(self):
-        with warnings.catch_warnings():
-            warnings.simplefilter("ignore", DeprecationWarning)
-
-            self.assertMessages('assertDictContainsSubset', ({'key': 'value'}, {}),
-                                ["^Missing: 'key'$", "^oops$",
-                                 "^Missing: 'key'$",
-                                 "^Missing: 'key' : oops$"])
-
     def testAssertMultiLineEqual(self):
         self.assertMessages('assertMultiLineEqual', ("", "foo"),
                             [r"\+ foo$", "^oops$",

Modified: python/branches/py3k/Lib/unittest/test/test_case.py
==============================================================================
--- python/branches/py3k/Lib/unittest/test/test_case.py	(original)
+++ python/branches/py3k/Lib/unittest/test/test_case.py	Sun Feb 20 12:18:09 2011
@@ -488,36 +488,6 @@
         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 = [
                 ((), ()),
@@ -1094,20 +1064,11 @@
         have to stay around for a few more versions.  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.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')),
         )
@@ -1115,19 +1076,6 @@
             with self.assertWarns(DeprecationWarning):
                 meth(*args)
 
-    def testDeprecatedFailMethods(self):
-        """Test that the deprecated fail* methods get removed in 3.3"""
-        if sys.version_info[:2] < (3, 3):
-            return
-        deprecated_names = [
-            'failIfEqual', 'failUnlessEqual', 'failUnlessAlmostEqual',
-            'failIfAlmostEqual', 'failUnless', 'failUnlessRaises', 'failIf',
-            'assertSameElements', 'assertDictContainsSubset',
-        ]
-        for deprecated_name in deprecated_names:
-            with self.assertRaises(AttributeError):
-                getattr(self, deprecated_name)  # remove these in 3.3
-
     def testDeepcopy(self):
         # Issue: 5660
         class TestableTest(unittest.TestCase):

Modified: python/branches/py3k/Lib/unittest/test/test_runner.py
==============================================================================
--- python/branches/py3k/Lib/unittest/test/test_runner.py	(original)
+++ python/branches/py3k/Lib/unittest/test/test_runner.py	Sun Feb 20 12:18:09 2011
@@ -257,19 +257,17 @@
             return [b.splitlines() for b in p.communicate()]
         opts = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                     cwd=os.path.dirname(__file__))
-        ae_msg = b'Please use assertEqual instead.'
-        at_msg = b'Please use assertTrue instead.'
 
         # no args -> all the warnings are printed, unittest warnings only once
         p = subprocess.Popen([sys.executable, '_test_warnings.py'], **opts)
         out, err = get_parse_out_err(p)
         self.assertIn(b'OK', err)
         # check that the total number of warnings in the output is correct
-        self.assertEqual(len(out), 12)
+        self.assertEqual(len(out), 11)
         # check that the numbers of the different kind of warnings is correct
         for msg in [b'dw', b'iw', b'uw']:
             self.assertEqual(out.count(msg), 3)
-        for msg in [ae_msg, at_msg, b'rw']:
+        for msg in [b'rw']:
             self.assertEqual(out.count(msg), 1)
 
         args_list = (
@@ -294,11 +292,9 @@
                              **opts)
         out, err = get_parse_out_err(p)
         self.assertIn(b'OK', err)
-        self.assertEqual(len(out), 14)
+        self.assertEqual(len(out), 13)
         for msg in [b'dw', b'iw', b'uw', b'rw']:
             self.assertEqual(out.count(msg), 3)
-        for msg in [ae_msg, at_msg]:
-            self.assertEqual(out.count(msg), 1)
 
     def testStdErrLookedUpAtInstantiationTime(self):
         # see issue 10786


More information about the Python-checkins mailing list