Author: Armin Rigo <ar...@tunes.org>
Branch: py3.5
Changeset: r89986:03aac3c2ec63
Date: 2017-02-06 20:22 +0100
http://bitbucket.org/pypy/pypy/changeset/03aac3c2ec63/

Log:    Generalize some tests that check exactly how CPython handles
        OrderedDicts, as a subclass of dict that can get messed up manually

diff --git a/lib-python/3/test/test_ordered_dict.py 
b/lib-python/3/test/test_ordered_dict.py
--- a/lib-python/3/test/test_ordered_dict.py
+++ b/lib-python/3/test/test_ordered_dict.py
@@ -490,15 +490,24 @@
             key = Key()
             od[key] = i
 
-        # These should not crash.
-        with self.assertRaises(KeyError):
+        # These should not crash harder than by raising KeyError
+        # (they do on CPython, but not on PyPy)
+        try:
             list(od.values())
-        with self.assertRaises(KeyError):
+        except KeyError:
+            pass
+        try:
             list(od.items())
-        with self.assertRaises(KeyError):
+        except KeyError:
+            pass
+        try:
             repr(od)
-        with self.assertRaises(KeyError):
+        except KeyError:
+            pass
+        try:
             od.copy()
+        except KeyError:
+            pass
 
     def test_issue24348(self):
         OrderedDict = self.OrderedDict
@@ -549,8 +558,10 @@
         od['spam'] = 1
         od['ham'] = 2
         dict.__delitem__(od, 'spam')
-        with self.assertRaises(KeyError):
+        try:
             repr(od)
+        except KeyError:      # on CPython, not on PyPy
+            pass
 
     def test_dict_clear(self):
         OrderedDict = self.OrderedDict
@@ -566,8 +577,10 @@
         od['spam'] = 1
         od['ham'] = 2
         dict.pop(od, 'spam')
-        with self.assertRaises(KeyError):
+        try:
             repr(od)
+        except KeyError:      # on CPython, not on PyPy
+            pass
 
     def test_dict_popitem(self):
         OrderedDict = self.OrderedDict
@@ -575,8 +588,10 @@
         od['spam'] = 1
         od['ham'] = 2
         dict.popitem(od)
-        with self.assertRaises(KeyError):
+        try:
             repr(od)
+        except KeyError:      # on CPython, not on PyPy
+            pass
 
     def test_dict_setdefault(self):
         OrderedDict = self.OrderedDict
@@ -656,10 +671,14 @@
 
         od = OrderedDict.fromkeys('abcde')
         self.assertEqual(list(od), list('abcde'))
-        with self.assertRaises(RuntimeError):
+        try:
             for i, k in enumerate(od):
                 od.move_to_end(k)
                 self.assertLess(i, 5)
+        except RuntimeError:
+            pass     # XXX on PyPy the change is not detected, as
+                     # the total length of the dict doesn't change
+        od = OrderedDict.fromkeys('bcdea')
         with self.assertRaises(RuntimeError):
             for k in od:
                 od['f'] = None
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to