示例#1
0
文件: test_ejson.py 项目: Yipit/ejson
def test_deserialization():
    ejson.cleanup_deserialization_registry()

    @ejson.register_deserializer(Person)
    def deserialize_person(data):
        return Person(data['name'], data['age'])

    obj = ejson.loads('{"age": 25, "name": "Lincoln"}')
    person = ejson.deserialize(Person, obj)
    person.should.be.a(Person)
    person.name.should.be.equals('Lincoln')
    person.age.should.be.equals(25)
示例#2
0
文件: test_ejson.py 项目: Yipit/ejson
def test_auto_deserialization():
    ejson.cleanup_deserialization_registry()

    @ejson.register_deserializer(Person)
    def deserialize_person(data):
        return Person(data['name'], data['age'])

    person = ejson.loads(
        '{"__class__": "tests.unit.test_ejson.Person", "__value__": {"age": 25, "name": "Lincoln"}}')
    person.should.be.a(Person)
    person.name.should.be.equals('Lincoln')
    person.age.should.be.equals(25)
示例#3
0
def test_deserialization():
    ejson.cleanup_deserialization_registry()

    @ejson.register_deserializer(Person)
    def deserialize_person(data):
        return Person(data['name'], data['age'])

    obj = ejson.loads('{"age": 25, "name": "Lincoln"}')
    person = ejson.deserialize(Person, obj)
    person.should.be.a(Person)
    person.name.should.be.equals('Lincoln')
    person.age.should.be.equals(25)
示例#4
0
def test_auto_deserialization():
    ejson.cleanup_deserialization_registry()

    @ejson.register_deserializer(Person)
    def deserialize_person(data):
        return Person(data['name'], data['age'])

    person = ejson.loads(
        '{"__class__": "tests.unit.test_ejson.Person", "__value__": {"age": 25, "name": "Lincoln"}}'
    )
    person.should.be.a(Person)
    person.name.should.be.equals('Lincoln')
    person.age.should.be.equals(25)
示例#5
0
文件: test_ejson.py 项目: Yipit/ejson
def test_deserialization_registry():
    ejson.cleanup_deserialization_registry()
    dict(ejson.DESERIALIZE_REGISTRY).should.be.equal({})

    @ejson.register_deserializer(Person)
    def deserialize_person(data):
        return Person(data['name'], data['age'])

    ejson.DESERIALIZE_REGISTRY.should.have.length_of(1)
    ejson.DESERIALIZE_REGISTRY[Person].should.be.equal(deserialize_person)

    # Testing the cleanup for real
    ejson.cleanup_deserialization_registry()
    ejson.DESERIALIZE_REGISTRY.should.have.length_of(0)
示例#6
0
def test_deserialization_registry():
    ejson.cleanup_deserialization_registry()
    dict(ejson.DESERIALIZE_REGISTRY).should.be.equal({})

    @ejson.register_deserializer(Person)
    def deserialize_person(data):
        return Person(data['name'], data['age'])

    ejson.DESERIALIZE_REGISTRY.should.have.length_of(1)
    ejson.DESERIALIZE_REGISTRY[Person].should.be.equal(deserialize_person)

    # Testing the cleanup for real
    ejson.cleanup_deserialization_registry()
    ejson.DESERIALIZE_REGISTRY.should.have.length_of(0)
示例#7
0
文件: test_ejson.py 项目: Yipit/ejson
def test_deserialization_with_no_objects_registered():
    ejson.cleanup_deserialization_registry()
    obj = ejson.loads('{"age": 25, "name": "Lincoln"}')
    ejson.deserialize.when.called_with(Person, obj).should.throw(
        TypeError,
        "There is no deserializer registered to handle instances of 'Person'")
示例#8
0
def test_deserialization_with_no_objects_registered():
    ejson.cleanup_deserialization_registry()
    obj = ejson.loads('{"age": 25, "name": "Lincoln"}')
    ejson.deserialize.when.called_with(Person, obj).should.throw(
        TypeError,
        "There is no deserializer registered to handle instances of 'Person'")