summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2011-12-21 12:38:17 +0100
committerLaurent Bachelier <laurent@bachelier.name>2011-12-21 12:38:17 +0100
commit9f22148647aeb9ced54a3f64670a0c05568d44f9 (patch)
treee3be96eb5e19131fd2748f9ee426840f3473f307
parentAdd support for integers (diff)
downloadffs-9f22148647aeb9ced54a3f64670a0c05568d44f9.tar.xz
Test for custom type handling
-rw-r--r--test.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/test.py b/test.py
index e58da08..4baa0e8 100644
--- a/test.py
+++ b/test.py
@@ -115,3 +115,34 @@ class FfsTest(TestCase):
lst2 = Dict(self.root, Router(lulz=str))
assert lst2['lulz'] == "43"
assert isinstance(lst2['lulz'], basestring)
+
+ def test_customTypeConv(self):
+ class Rot13(object):
+ """
+ Protect your data from hackers reading your memory!
+ """
+ def __init__(self, encstring):
+ self.encstring = encstring
+
+ def __str__(self):
+ return 'ENCRYPTED!'
+
+ def tostring(self):
+ return self.encstring.encode('rot13')
+
+ @classmethod
+ def fromstring(cls, string):
+ return cls(string.decode('rot13'))
+
+ rot13 = Rot13('yby')
+ assert rot13.tostring() == 'lol'
+ assert Rot13.fromstring('lol').tostring() == 'lol'
+
+ lst1 = Dict(self.root, Router(lulz=Rot13))
+ lst1['lulz'] = Rot13('yby')
+ assert lst1['lulz'].tostring() == 'lol'
+ assert isinstance(lst1['lulz'], Rot13)
+
+ lst2 = Dict(self.root, Router(lulz=str))
+ assert lst2['lulz'] == "lol"
+ assert isinstance(lst2['lulz'], basestring)