File: test_nesting.py

package info (click to toggle)
python-serializable 0.2.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 156 kB
  • sloc: python: 483; makefile: 11
file content (37 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from serializable import to_serializable_repr, from_serializable_repr, Serializable
from nose.tools import eq_

class A(Serializable):
    def __init__(self, a_val):
        self.a = a_val

    def to_dict(self):
        return {"a_val": self.a}

class B(Serializable):
    def __init__(self, set_a_vals=set([A(1), A(2)])):
        self.set_a_vals = set_a_vals

    def to_dict(self):
        return {"set_a_vals": self.set_a_vals}


def test_list_of_lists():
    x = [[1, 2], ["hello", "wookies"], [A(1), A(2)]]
    eq_(x, from_serializable_repr(to_serializable_repr(x)))

def test_dict_of_lists():
    x = {"a": [1, 2, 3], "b": ["hello", "goodbye"], "1": [A(1), A(2)]}
    eq_(x, from_serializable_repr(to_serializable_repr(x)))

def test_dict_with_tuple_keys():
    x = {(1, 2): "hello"}
    eq_(x, from_serializable_repr(to_serializable_repr(x)))

def test_object_with_dict_values():
    x = A(dict(snooze=5))
    eq_(x, from_serializable_repr(to_serializable_repr(x)))

def test_object_with_set_values():
    x = B()
    eq_(x, from_serializable_repr(to_serializable_repr(x)))