Пример #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"]'