Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Regression test and patch for ticket #20924.

  • Loading branch information...
commit b9ef96e73cf2f2613eb6ca96038ef8c4271ac116 1 parent bc5716f
Nick Bruun authored August 15, 2013
8  django/utils/functional.py
@@ -270,6 +270,14 @@ def __setitem__(self, key, value):
270 270
     def __delitem__(self, key):
271 271
         del self[key]
272 272
 
  273
+    @new_method_proxy
  274
+    def __len__(self):
  275
+        return len(self)
  276
+
  277
+    @new_method_proxy
  278
+    def __contains__(self, key):
  279
+        return key in self
  280
+
273 281
 
274 282
 # Workaround for http://bugs.python.org/issue12370
275 283
 _super = super
13  tests/utils_tests/test_simplelazyobject.py
@@ -136,6 +136,9 @@ def test_dict(self):
136 136
         self.assertEqual(lazydict['one'], 1)
137 137
         lazydict['one'] = -1
138 138
         self.assertEqual(lazydict['one'], -1)
  139
+        self.assertTrue('one' in lazydict)
  140
+        self.assertFalse('two' in lazydict)
  141
+        self.assertEqual(len(lazydict), 1)
139 142
         del lazydict['one']
140 143
         with self.assertRaises(KeyError):
141 144
             lazydict['one']
@@ -183,3 +186,13 @@ def test_pickle_py2_regression(self):
183 186
 
184 187
             # This would fail with "TypeError: expected string or Unicode object, NoneType found".
185 188
             pickled = cPickle.dumps(x)
  189
+
  190
+    def test_list_set(self):
  191
+        lazy_list = SimpleLazyObject(lambda: [1, 2, 3, 4, 5])
  192
+        lazy_set = SimpleLazyObject(lambda: set([1, 2, 3, 4]))
  193
+        self.assertTrue(1 in lazy_list)
  194
+        self.assertTrue(1 in lazy_set)
  195
+        self.assertFalse(6 in lazy_list)
  196
+        self.assertFalse(6 in lazy_set)
  197
+        self.assertEqual(len(lazy_list), 5)
  198
+        self.assertEqual(len(lazy_set), 4)

0 notes on commit b9ef96e

Please sign in to comment.
Something went wrong with that request. Please try again.