[ZCM] [ZC] 664/ 3 Reject "ZTUtils/Iterator last and first not working"

Collector: Zope Bugs, Features, and Patches ... zope-coders@zope.org
Wed, 06 Nov 2002 10:07:14 -0500


Issue #664 Update (Reject) "ZTUtils/Iterator last and first not working"
 Status Rejected, Zope/bug medium
To followup, visit:
  http://collector.zope.org/Zope/664

==============================================================
= Reject - Entry #3 by stevea on Nov 6, 2002 10:07 am

 Status: Pending => Rejected

Ok, looks like I got confused between "first" and "last", and "start" and "end".

repeat/name/start and repeat/name/end do just want I need.


________________________________________
= Comment - Entry #2 by stevea on Nov 6, 2002 6:31 am

Here's a patch to ZTUtils/testIterator.py that shows the problem.

@@ -88,6 +89,15 @@
         it = Iterator([1])
         it.next()
         assert it.first() == it.last() == 1, "Bad first/last on singleton"
+
+        it = Iterator([1,2])
+        it.next()
+        assert it.first() == 1
+        assert it.last() == 0
+        it.next()
+        assert it.first() == 0
+        assert it.last() == 1
+
         four = range(4)
         for a in 2,3:
             for b in four:

[steve@localhost tests]$ python2.2 run.py
....F...................
======================================================================
FAIL: testFirstLast (testIterator.IteratorTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "testIterator.py", line 96, in testFirstLast
    assert it.last() == 0
AssertionError

----------------------------------------------------------------------
Ran 24 tests in 0.056s

FAILED (failures=1)
________________________________________
= Request - Entry #1 by stevea on Nov 6, 2002 6:24 am

First, a minor bug:

ZTUtils/tests/testIterator.py

it contains the code:

 if __name__=='__main__':
     main()

but it has no main() method.

Now, for the real bug. Iterating over a list in a page template using Zope on Python2.2.2, I can't get the repeat/name/first and repeat/name/last to work properly.

Here's a page template that demonstrates the problem:

 <html>
 <body>
 <p tal:repeat="r python:range(5)">
   <span tal:content="r" />
   first=<span tal:content="repeat/r/first" />
   last=<span tal:content="repeat/r/last" />
 </p>
 </body>
 </html>

The output is:

 0 first=1 last=1
 1 first=1 last=1
 2 first=1 last=1
 3 first=1 last=1
 4 first=1 last=1 

The expected output is:

 0 first=1 last=0
 1 first=0 last=0
 2 first=0 last=0
 3 first=0 last=0
 4 first=0 last=1 

==============================================================