예제 #1
0
def test_set_json():
    a = {True, 5.5, 5, None, 'hello'}
    s = JsonSerializer()
    r = s.serialize(a)
    # sets are unordered, and, it turns out, not deterministic
    # TODO bit of a bodge
    r = json.loads(r)
    r = sorted([str(x) for x in r])
    assert r == ['5', '5.5', 'None', 'True', 'hello']
def test_from_import():
    from emw_serializer import JsonSerializer, Serializer
    js = JsonSerializer()
    s = Serializer()
예제 #3
0
from emw_serializer import JsonSerializer


class Gakk:
    def __init__(self):
        self.a = 'a'
        self.b = 5


serializer = JsonSerializer()
thing_to_serialize = Gakk()
json = serializer.serialize(thing_to_serialize)
print(json)
예제 #4
0
def test_string_json():
    a = 'hello'
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '"hello"'
예제 #5
0
def test_int_json():
    a = 5
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '5'
예제 #6
0
def test_bool_json():
    a = True
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == 'true'
예제 #7
0
def test_float_json():
    a = 5.5
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '5.5'
예제 #8
0
def test_method_json():
    a = Method()
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '{"a": 5}'
예제 #9
0
def test_class_properties_json():
    a = ClassProperties()
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '{"a": true, "b": 5.5, "c": 5, "d": null, "e": "hello", "f": "", "g": "Good"}'
예제 #10
0
def test_nested_json():
    a = Nested()
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '{"a": 5, "b": {"a": true, "b": 5.5, "c": 5, "d": null, "e": "hello", "f": "", "g": "Good"}, "c": [1, "hello"]}'
예제 #11
0
def test_property_function_json():
    a = PropertyFunction()
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '{"nope": "nope"}'
예제 #12
0
def test_property_decorator_json():
    a = PropertyDecorator()
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '{"nope": "nope"}'
예제 #13
0
def test_inheritance_method_json():
    a = InheritanceMethod()
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '{"a": 5}'
예제 #14
0
def test_inheritance_object_properties_json():
    a = InheritanceObjectProperties()
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '{"a": true, "b": 5.5, "c": 5, "d": null, "e": "hello", "f": "", "g": "Good"}'
예제 #15
0
def test_list_json():
    a = [True, 5.5, 5, None, 'hello']
    s = JsonSerializer()
    r = s.serialize(a)
    assert r == '[true, 5.5, 5, null, "hello"]'