summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2011-12-28 18:49:38 +0100
committerLaurent Bachelier <laurent@bachelier.name>2011-12-28 18:49:38 +0100
commit6840ba865cf5aefe2b4b4461214a08eb7f3e2106 (patch)
tree22b75d0b212e7ac7f0eeaedf3d5887684d613db5
parentQuote consistency (diff)
downloadffs-6840ba865cf5aefe2b4b4461214a08eb7f3e2106.tar.xz
Add test for mutable objects saving
-rw-r--r--test.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/test.py b/test.py
index 2b9c709..a38541c 100644
--- a/test.py
+++ b/test.py
@@ -229,3 +229,38 @@ class FfsTest(TestCase):
dct1['looool'] = []
assert 'looool' in dct1
assert len(dl1) == 0
+
+ def test_mutableSave(self):
+ class MutableObject(object):
+ def __init__(self, v):
+ self.v = v
+
+ def tostring(self):
+ return self.v
+
+ @classmethod
+ def fromstring(cls, v):
+ return cls(v)
+
+ assert MutableObject.fromstring("lol").tostring() == "lol"
+ m = MutableObject("loool")
+ assert m.v == "loool"
+
+ dct1 = Dict(self.root, Router(lulz=MutableObject))
+ dct1['lulz'] = m
+ assert dct1['lulz'].v == "loool"
+ assert dct1['lulz'] is not m
+
+ # change a value in the mutable object
+ m.v = "lulz"
+ # it's not changed in the list, even in the same Dict object,
+ # because we keep nothing in memory
+ assert dct1['lulz'].v != "lulz"
+ assert dct1['lulz'] is not m
+ # it should force a save on disk
+ dct1['lulz'] = m
+ assert dct1['lulz'].v == "lulz"
+ assert dct1['lulz'] is not m
+ dct2 = Dict(self.root, Router(lulz=MutableObject))
+ assert dct2['lulz'].v == "lulz"
+ assert dct1['lulz'] is not m