Created
January 20, 2013 22:46
-
-
Save uruz/4582334 to your computer and use it in GitHub Desktop.
django.utils.functional.lazy issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tests/regressiontests/utils/functional.py b/tests/regressiontests/utils/functional.py | |
index 90a6f08..07d26af 100644 | |
--- a/tests/regressiontests/utils/functional.py | |
+++ b/tests/regressiontests/utils/functional.py | |
@@ -1,5 +1,6 @@ | |
from django.utils import unittest | |
from django.utils.functional import lazy, lazy_property | |
+from django.utils import six | |
class FunctionalTestCase(unittest.TestCase): | |
@@ -37,3 +38,46 @@ class FunctionalTestCase(unittest.TestCase): | |
self.assertRaises(NotImplementedError, lambda: A().do) | |
self.assertEqual(B().do, 'DO IT') | |
+ | |
+ def test_lazy_magicmethods_mod(self): | |
+ class A(six.text_type): | |
+ def __mod__(self, rhs): | |
+ return 'Result: ' + super(A, self).__mod__(rhs) | |
+ | |
+ t = lazy(lambda: A('Hello %(word)s'), A)() | |
+ self.assertEqual(t % {'word': 'world'}, 'Result: Hello world') | |
+ | |
+ def test_lazy_magicmethods_hash(self): | |
+ class NotAHashable(object): | |
+ __hash__ = None | |
+ | |
+ notahash = NotAHashable() | |
+ notahash_lazy = lazy(lambda: NotAHashable(), NotAHashable)() | |
+ self.assertRaises(TypeError, lambda: {notahash: 1}) | |
+ self.assertRaises(TypeError, lambda: {notahash_lazy: 2}) | |
+ | |
+ def test_lazy_losing_docstring(self): | |
+ class A(object): | |
+ def hello(self): | |
+ '''Docstring''' | |
+ return 'Hello world' | |
+ lazy_a = lazy(lambda: A(), A)() | |
+ self.assertEqual(lazy_a.hello.__doc__, 'Docstring') | |
+ | |
+ def test_lazy_attributes(self): | |
+ class A(object): | |
+ counter = 15 | |
+ | |
+ lazy_a = lazy(lambda: A(), A)() | |
+ self.assertEqual(lazy_a.counter, 15) | |
+ lazy_a.counter = 16 | |
+ self.assertEqual(lazy_a.counter, 16) | |
+ | |
+ class B(object): | |
+ @property | |
+ def counter(self): | |
+ return 15 | |
+ | |
+ lazy_b = lazy(lambda: B(), B)() | |
+ self.assertEqual(lazy_b.counter, 15) | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment