[Python-checkins] cpython (3.2): Issue 3051: make pure python code pass the same tests as the C version.

raymond.hettinger python-checkins at python.org
Wed Apr 13 20:51:05 CEST 2011


http://hg.python.org/cpython/rev/83e4765ec4cb
changeset:   69332:83e4765ec4cb
branch:      3.2
parent:      69329:f5672fbc7727
user:        Raymond Hettinger <python at rcn.com>
date:        Wed Apr 13 11:49:57 2011 -0700
summary:
  Issue 3051: make pure python code pass the same tests as the C version.

files:
  Lib/heapq.py           |   9 ++++-----
  Lib/test/test_heapq.py |  16 +++++-----------
  2 files changed, 9 insertions(+), 16 deletions(-)


diff --git a/Lib/heapq.py b/Lib/heapq.py
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -212,11 +212,10 @@
         pop = result.pop
         los = result[-1]    # los --> Largest of the nsmallest
         for elem in it:
-            if los <= elem:
-                continue
-            insort(result, elem)
-            pop()
-            los = result[-1]
+            if elem < los:
+                insort(result, elem)
+                pop()
+                los = result[-1]
         return result
     # An alternative approach manifests the whole iterable in memory but
     # saves comparisons by heapifying all at once.  Also, saves time
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -211,12 +211,6 @@
         self.assertEqual(hsort(data, LT), target)
         self.assertRaises(TypeError, data, LE)
 
-    # As an early adopter, we sanity check the
-    # test.support.import_fresh_module utility function
-    def test_accelerated(self):
-        self.assertTrue(sys.modules['heapq'] is self.module)
-        self.assertFalse(hasattr(self.module.heapify, '__code__'))
-
 
 #==============================================================================
 
@@ -319,16 +313,16 @@
 
     def test_non_sequence(self):
         for f in (self.module.heapify, self.module.heappop):
-            self.assertRaises(TypeError, f, 10)
+            self.assertRaises((TypeError, AttributeError), f, 10)
         for f in (self.module.heappush, self.module.heapreplace,
                   self.module.nlargest, self.module.nsmallest):
-            self.assertRaises(TypeError, f, 10, 10)
+            self.assertRaises((TypeError, AttributeError), f, 10, 10)
 
     def test_len_only(self):
         for f in (self.module.heapify, self.module.heappop):
-            self.assertRaises(TypeError, f, LenOnly())
+            self.assertRaises((TypeError, AttributeError), f, LenOnly())
         for f in (self.module.heappush, self.module.heapreplace):
-            self.assertRaises(TypeError, f, LenOnly(), 10)
+            self.assertRaises((TypeError, AttributeError), f, LenOnly(), 10)
         for f in (self.module.nlargest, self.module.nsmallest):
             self.assertRaises(TypeError, f, 2, LenOnly())
 
@@ -353,7 +347,7 @@
         for f in (self.module.heapify, self.module.heappop,
                   self.module.heappush, self.module.heapreplace,
                   self.module.nlargest, self.module.nsmallest):
-            self.assertRaises(TypeError, f, 10)
+            self.assertRaises((TypeError, AttributeError), f, 10)
 
     def test_iterable_args(self):
         for f in (self.module.nlargest, self.module.nsmallest):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list