diff options
author | Jauhien Piatlicki <jauhien@gentoo.org> | 2015-04-18 19:21:21 +0200 |
---|---|---|
committer | Jauhien Piatlicki <jauhien@gentoo.org> | 2015-04-18 22:03:58 +0200 |
commit | 4b58d04be635a430c6e24666ac43c92fbd79af73 (patch) | |
tree | 69c5997b199a0f5cd375a5323abfdaf7e4cbd680 /tests/serializable.py | |
parent | [setup] fix copyright (diff) | |
download | g-sorcery-4b58d04be635a430c6e24666ac43c92fbd79af73.tar.gz g-sorcery-4b58d04be635a430c6e24666ac43c92fbd79af73.tar.bz2 g-sorcery-4b58d04be635a430c6e24666ac43c92fbd79af73.zip |
[g_sorcery/serialization] fix serialization for collections
Diffstat (limited to 'tests/serializable.py')
-rw-r--r-- | tests/serializable.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/serializable.py b/tests/serializable.py new file mode 100644 index 0000000..1d3981e --- /dev/null +++ b/tests/serializable.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + serializable.py + ~~~~~~~~~~~~~~~ + + test classes for serialization + + :copyright: (c) 2013-2015 by Jauhien Piatlicki + :license: GPL-2, see LICENSE for more details. +""" + +class NonSerializableClass(object): + pass + + +class SerializableClass(object): + + __slots__ = ("field1", "field2") + + def __init__(self, field1, field2): + self.field1 = field1 + self.field2 = field2 + + def __eq__(self, other): + return self.field1 == other.field1 \ + and self.field2 == other.field2 + + def serialize(self): + return {"field1": self.field1, "field2": self.field2} + + +class DeserializableClass(SerializableClass): + + @classmethod + def deserialize(cls, value): + return DeserializableClass(value["field1"], value["field2"]) |