summaryrefslogtreecommitdiff
path: root/tests/test_support.py
diff options
context:
space:
mode:
authorastaric <anze.staric@gmail.com>2014-06-12 09:33:36 +0200
committerastaric <anze.staric@gmail.com>2015-08-05 18:21:00 +0200
commita1cc3f1ca8149cddd97bd6823857cc9e3eba544e (patch)
treee3c1274701ac51feb91985b7f568dbc51d28db93 /tests/test_support.py
parent5c073d75a581a178c4679a073553c589d79c1d7e (diff)
downloadbabel-a1cc3f1ca8149cddd97bd6823857cc9e3eba544e.tar.gz
Add __copy__ and __deepcopy__ to LazyProxy.
Python's copy.copy and copy.deepcopy do not call objects __init__, resulting in endless recursion.
Diffstat (limited to 'tests/test_support.py')
-rw-r--r--tests/test_support.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_support.py b/tests/test_support.py
index 8c182fc..4647f6b 100644
--- a/tests/test_support.py
+++ b/tests/test_support.py
@@ -243,6 +243,33 @@ class LazyProxyTestCase(unittest.TestCase):
self.assertEqual(1, proxy.value)
self.assertEqual(2, proxy.value)
+ def test_can_copy_proxy(self):
+ from copy import copy
+
+ numbers = [1,2]
+ def first(xs):
+ return xs[0]
+
+ proxy = support.LazyProxy(first, numbers)
+ proxy_copy = copy(proxy)
+
+ numbers.pop(0)
+ self.assertEqual(2, proxy.value)
+ self.assertEqual(2, proxy_copy.value)
+
+ def test_can_deepcopy_proxy(self):
+ from copy import deepcopy
+ numbers = [1,2]
+ def first(xs):
+ return xs[0]
+
+ proxy = support.LazyProxy(first, numbers)
+ proxy_deepcopy = deepcopy(proxy)
+
+ numbers.pop(0)
+ self.assertEqual(2, proxy.value)
+ self.assertEqual(1, proxy_deepcopy.value)
+
def test_format_date():
fmt = support.Format('en_US')