Exemplo n.º 1
0
def test_to_json_with_obj_without_id():
    class Obj(object):
        pass

    d = {'i': Obj()}
    with pytest.raises(TypeError):
        to_json(d)
Exemplo n.º 2
0
def test_to_json_with_numpy():
    class FakeNumpyFloat(object):
        def item(self):
            return 0.666

    d = {'float': FakeNumpyFloat()}
    assert to_json(d) == '{"float": 0.666}'
Exemplo n.º 3
0
def test_to_json():
    d = {
        'i': 42,
        's': 'string',
        'dt': datetime.datetime.now(),
        'id': uuid.uuid4()
    }
    assert isinstance(to_json(d), basestring)
Exemplo n.º 4
0
def test_from_json():
    d = {
        'i': 42,
        's': 'string',
        'dt': datetime.datetime.now(),
        'id': uuid.uuid4()
    }
    assert isinstance(from_json(to_json(d)), dict)
Exemplo n.º 5
0
def test_to_json_with_obj_with_id():
    class Obj(object):
        id = '42'

    d = {'i': Obj()}
    assert isinstance(to_json(d), basestring)