Ticket #12506: diff.diff

File diff.diff, 2.0 KB (added by Alex Gaynor, 15 years ago)
  • django/utils/functional.py

    diff --git a/django/utils/functional.py b/django/utils/functional.py
    index 43b7ab1..e52ab76 100644
    a b def lazy(func, *resultclasses):  
    167167            for resultclass in resultclasses:
    168168                cls.__dispatch[resultclass] = {}
    169169                for (k, v) in resultclass.__dict__.items():
     170                    # All __promise__ return the same wrapper method, but they
     171                    # also do setup, inserting the method into the dispatch
     172                    # dict.
     173                    meth = cls.__promise__(resultclass, k, v)
    170174                    if hasattr(cls, k):
    171175                        continue
    172                     setattr(cls, k, cls.__promise__(resultclass, k, v))
     176                    setattr(cls, k, meth)
    173177            cls._delegate_str = str in resultclasses
    174178            cls._delegate_unicode = unicode in resultclasses
    175179            assert not (cls._delegate_str and cls._delegate_unicode), "Cannot call lazy() with both str and unicode return types."
  • new file tests/regressiontests/utils/functional.py

    diff --git a/tests/regressiontests/utils/functional.py b/tests/regressiontests/utils/functional.py
    new file mode 100644
    index 0000000..7261015
    - +  
     1from unittest import TestCase
     2
     3from django.utils.functional import lazy
     4
     5
     6class FunctionalTestCase(TestCase):
     7    def test_lazy(self):
     8        t = lazy(lambda: tuple(range(3)), list, tuple)
     9        for a, b in zip(t(), range(3)):
     10            self.assertEqual(a, b)
  • tests/regressiontests/utils/tests.py

    diff --git a/tests/regressiontests/utils/tests.py b/tests/regressiontests/utils/tests.py
    index fe5f463..cd93fb9 100644
    a b import datastructures  
    1212import itercompat
    1313
    1414from decorators import DecoratorFromMiddlewareTests
     15from functional import FunctionalTestCase
    1516
    1617# We need this because "datastructures" uses sorted() and the tests are run in
    1718# the scope of this module.
Back to Top