示例#1
0
def _assert_serialize_deserialize_equals_and_is_binary(
    ejson_obj, json_obj, json_str, is_binary
):
    assert json_str == ejson.stringify(ejson_obj)
    assert json_str == ejson.dumps(ejson_obj)
    assert json_obj == ejson.to_json_value(ejson_obj)

    assert ejson_obj == ejson.parse(json_str)
    assert ejson_obj == ejson.loads(json_str)
    assert ejson_obj == ejson.from_json_value(json_obj)

    ejson_obj2 = deepcopy(ejson_obj)

    assert ejson.equals(ejson_obj, ejson_obj2)
    assert ejson.equals(ejson_obj, ejson.clone(ejson_obj))
    assert is_binary == ejson.is_binary(ejson_obj)
示例#2
0
def test_clone(ejsonobj, json):
    clone = ejson.clone(ejsonobj)

    assert clone == ejsonobj

    # clone() must return a value r such that r.__eq__(r) is always True,
    # even if r is later modified.
    if isinstance(ejsonobj, ejson.Date):
        ejsonobj += timedelta(hours=1)        
    elif isinstance(ejsonobj, ejson.Binary):
        ejsonobj[:0] = b'x'
    elif isinstance(ejsonobj, dict): # is JSON object
        # Change the value of the first key.
        assert ejsonobj[ejsonobj.keys()[0]] != 'x'
        ejsonobj[ejsonobj.keys()[0]] = 'x'
    else:
        assert False # You need to implement this for your new type.

    assert clone == clone
    assert clone != ejsonobj