[Checkins] SVN: zc.blist/trunk/src/zc/blist/ fixed access to items at the ends of the valid index range

Thomas Lotze tl at gocept.com
Wed Mar 11 13:09:45 EDT 2009


Log message for revision 97908:
  fixed access to items at the ends of the valid index range

Changed:
  U   zc.blist/trunk/src/zc/blist/CHANGES.txt
  U   zc.blist/trunk/src/zc/blist/__init__.py
  U   zc.blist/trunk/src/zc/blist/regression.txt

-=-
Modified: zc.blist/trunk/src/zc/blist/CHANGES.txt
===================================================================
--- zc.blist/trunk/src/zc/blist/CHANGES.txt	2009-03-11 17:08:01 UTC (rev 97907)
+++ zc.blist/trunk/src/zc/blist/CHANGES.txt	2009-03-11 17:09:44 UTC (rev 97908)
@@ -6,7 +6,10 @@
 
 - removed unused code and the dependency on rwproperty
 
+- improved test coverage of the BList API, fixed access to items at index -1
+  or at the ends of the valid index range
 
+
 1.0b1 (2008-10-06)
 ==================
 

Modified: zc.blist/trunk/src/zc/blist/__init__.py
===================================================================
--- zc.blist/trunk/src/zc/blist/__init__.py	2009-03-11 17:08:01 UTC (rev 97907)
+++ zc.blist/trunk/src/zc/blist/__init__.py	2009-03-11 17:09:44 UTC (rev 97908)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2007-2008 Zope Corporation and Contributors.
+# Copyright (c) 2007-2009 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -478,7 +478,7 @@
     # Everything relies on __setitem__ to reduce duplicated logic
 
     def append(self, value):
-        self[len(self)] = value
+        self[len(self):] = (value,)
 
     def insert(self, index, value):
         self[index:index] = (value,)
@@ -601,13 +601,11 @@
         # To reduce the amount of duplicated code, everything is based on
         # slices. Either you are replacing specific items (index is an integer
         # less than len or a slice with an explicit step) or deleting/inserting
-        # ranges (index is an integer equal to len or a slice with an implicit
-        # step of 1).  We convert integer requests to slice requests here.
+        # ranges (index is a slice with an implicit step of 1). We convert
+        # integer requests to slice requests here.
         if not isinstance(index, slice):
             value = (value,)
-            if index == length:
-                index = slice(length, length)
-            elif index > length:
+            if index >= length or index < -length:
                 raise IndexError('list assignment index out of range')
             elif index == -1:
                 index = slice(length-1, length, 1) # we specify a step to use

Modified: zc.blist/trunk/src/zc/blist/regression.txt
===================================================================
--- zc.blist/trunk/src/zc/blist/regression.txt	2009-03-11 17:08:01 UTC (rev 97907)
+++ zc.blist/trunk/src/zc/blist/regression.txt	2009-03-11 17:09:44 UTC (rev 97908)
@@ -64,9 +64,9 @@
     >>> list(b[:])
     [11, 99]
     >>> b[0] = 0
-    >>> b[2] = 100
-    >>> b[3] = 101
-    >>> b[4] = 102
+    >>> b.append(100)
+    >>> b.append(101)
+    >>> b.append(102)
     >>> matches(b, [0, 99, 100, 101, 102])
     True
 
@@ -139,6 +139,29 @@
     >>> len(b)
     1000
 
+Regression tests for accessing items at the edges of the valid index range
+(which would also fail in 1.0b1):
+
+    >>> b[1000]
+    Traceback (most recent call last):
+    IndexError: list index out of range
+    >>> b[1000] = None
+    Traceback (most recent call last):
+    IndexError: list assignment index out of range
+    >>> del b[1000]
+    Traceback (most recent call last):
+    IndexError: list assignment index out of range
+
+    >>> b[-1001]
+    Traceback (most recent call last):
+    IndexError: list index out of range
+    >>> b[-1001] = None
+    Traceback (most recent call last):
+    IndexError: list assignment index out of range
+    >>> del b[-1001]
+    Traceback (most recent call last):
+    IndexError: list assignment index out of range
+
 These are some more stress and regression tests.
 
     >>> del b[900:]



More information about the Checkins mailing list