Edgewall Software

Ticket #324 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

Test fails for Genshi-0.5.1 and Python 2.6.2

Reported by: neurogeek@… Owned by: cmlenz
Priority: trivial Milestone: 0.6
Component: General Version: 0.5.1
Keywords: Cc: lmacken@…

Description

Hello there,

When running python setup.py test in Genshi-0.5.1 using python-2.6.2, I get a test failed for genshi.template.eval.Undefined in here:

"""Represents a reference to an undefined variable.
221	   
227	    >>> foo = Undefined('foo')
228	    >>> bool(foo)
229	    False
230	    >>> list(foo) -----> This line fail test
231	    []
232	    >>> print foo
233	    undefined

Thanks,

Attachments

python-genshi-0.5.1-py2.6.2-length_hint.patch Download (492 bytes) - added by lmacken@… 5 years ago.
python-genshi-0.5.1-py2.6.2-length_hint.patch

Change History

Changed 5 years ago by lmacken@…

  • cc lmacken@… added

When tweaking the class a little and running the tests::

    python-2.4.3-27.el5
    -------------------
    Failed example: list(foo)
    Expected: []
    Got:
        Undefined.__iter__
        []

    python-2.6.2-2.fc12
    ------------------------
    Failed example: list(foo)
    Expected: []
    Got:
        Undefined.__iter__
        __getattr__(('__length_hint__',))
        []

Since the Undefined class overloads sets __getattr__ = _die, this causes some unexpected behavior on Python 2.6.2

I'm thinking that this behavior was introduced in:  http://bugs.python.org/issue1242657 Another example of this behavior can be found in the test case that came along with it:  http://svn.python.org/view/python/trunk/Lib/test/test_iterlen.py?r1=69227&r2=69226&pathrev=69227

I threw together the following patch for Fedora that gets the test suite running again:

--- genshi/template/eval.py.orig	2009-09-11 17:09:13.589445262 -0400
+++ genshi/template/eval.py	2009-09-11 17:11:17.818691489 -0400
@@ -279,6 +279,10 @@
         raise UndefinedError(self._name, self._owner)
     __call__ = __getattr__ = __getitem__ = _die
 
+    # Hack around some behavior introduced in Python 2.6.2
+    # http://genshi.edgewall.org/ticket/324
+    __length_hint__ = None
+
 
 class LookupBase(object):
     """Abstract base class for variable lookup implementations."""

Changed 5 years ago by lmacken@…

python-genshi-0.5.1-py2.6.2-length_hint.patch

Changed 4 years ago by cmlenz

  • milestone changed from 0.6 to 0.6.1

Changed 4 years ago by rblank

Another (much less elegant) patch is in comment:6:ticket:370.

Changed 4 years ago by cmlenz

  • status changed from new to assigned
  • milestone changed from 0.6.1 to 0.6

Issue raised again in #370.

Changed 4 years ago by cmlenz

  • status changed from assigned to closed
  • resolution set to fixed

Applied in [1101]. Thanks and sorry for the wait!

Add/Change #324 (Test fails for Genshi-0.5.1 and Python 2.6.2)

Author


E-mail address and user name can be saved in the Preferences.


Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.