Esempio n. 1
0
def test_instance_jitted_instance_marshal_method_supports_none_int(
        simple_schema, simple_object):
    simple_object.value = None
    marshal_method = generate_marshall_method(simple_schema)
    result = marshal_method(simple_object)
    expected = {'key': 'some_key', 'value': None}
    assert expected == result
Esempio n. 2
0
def test_nested_marshal_method(nested_schema):
    marshal_method = generate_marshall_method(nested_schema)
    result = marshal_method({
        'key':
        'some_key',
        'value': {
            'name': 'sub_key',
            'value': {
                'bar': 'frob',
                'raz': 'blah'
            }
        },
        'values': [{
            'name': 'first_child',
            'value': 'foo'
        }, {
            'name': 'second_child',
            'value': 'bar'
        }]
    })
    expected = {
        'key': 'some_key',
        'value': {
            'name': 'sub_key',
            'value': {
                'bar': 'frob'
            }
        },
        'values': [{
            'name': 'first_child',
        }, {
            'name': 'second_child'
        }]
    }
    assert expected == result
Esempio n. 3
0
def test_jit_bails_with_get_attribute():
    class DynamicSchema(Schema):
        def get_attribute(self, obj, attr, default):
            pass

    marshal_method = generate_marshall_method(DynamicSchema())
    assert marshal_method is None
Esempio n. 4
0
def test_hybrid_jitted_marshal_method(simple_schema, simple_hybrid,
                                      simple_dict):
    marshal_method = generate_marshall_method(simple_schema, threshold=1)
    result = marshal_method(simple_hybrid)
    assert simple_dict == result
    result = marshal_method(simple_hybrid)
    assert simple_dict == result
    assert marshal_method.proxy._call == marshal_method.proxy.hybrid_serializer
Esempio n. 5
0
def test_non_primitive_num_type_schema(non_primitive_num_type_schema):
    context = JitContext()
    marshall_method = generate_marshall_method(non_primitive_num_type_schema,
                                               threshold=1,
                                               context=context)
    result = marshall_method({})
    expected = {}
    assert expected == result
Esempio n. 6
0
def test_instance_jitted_instance_marshal_method(simple_schema, simple_object,
                                                 simple_dict):
    marshal_method = generate_marshall_method(simple_schema, threshold=1)
    result = marshal_method(simple_object)
    assert simple_dict == result
    result = marshal_method(simple_object)
    assert simple_dict == result
    assert (
        marshal_method.proxy._call == marshal_method.proxy.instance_serializer)
Esempio n. 7
0
def test_jitted_marshal_method(schema):
    context = JitContext()
    marshal_method = generate_marshall_method(schema,
                                              threshold=1,
                                              context=context)
    result = marshal_method({'@#': 32, 'bar': 'Hello', 'meh': 'Foo'})
    expected = {'bar': u'Hello', 'foo': 32, 'raz': 'Hello!'}
    assert expected == result
    # Test specialization
    result = marshal_method({'@#': 32, 'bar': 'Hello', 'meh': 'Foo'})
    assert expected == result
    assert marshal_method.proxy._call == marshal_method.proxy.dict_serializer
Esempio n. 8
0
def test_jitted_marshal_method_bails_on_specialize(simple_schema,
                                                   simple_object, simple_dict,
                                                   simple_hybrid):
    marshal_method = generate_marshall_method(simple_schema, threshold=2)
    assert simple_dict == marshal_method(simple_dict)
    assert marshal_method.proxy._call == marshal_method.proxy.tracing_call
    assert simple_dict == marshal_method(simple_object)
    assert marshal_method.proxy._call == marshal_method.proxy.no_tracing_call
    assert simple_dict == marshal_method(simple_object)
    assert marshal_method.proxy._call == marshal_method.proxy.no_tracing_call
    assert simple_dict == marshal_method(simple_dict)
    assert marshal_method.proxy._call == marshal_method.proxy.no_tracing_call
    assert simple_dict == marshal_method(simple_hybrid)
    assert marshal_method.proxy._call == marshal_method.proxy.no_tracing_call
Esempio n. 9
0
def test_nested_marshal_method_circular_ref(nested_circular_ref_schema):
    marshal_method = generate_marshall_method(nested_circular_ref_schema)
    result = marshal_method({'key': 'some_key', 'me': {'key': 'sub_key'}})
    expected = {'key': 'some_key', 'me': {'key': 'sub_key'}}
    assert expected == result
Esempio n. 10
0
def test_optimized_jitted_marshal_method(optimized_schema, simple_object):
    marshal_method = generate_marshall_method(optimized_schema)
    result = marshal_method(simple_object)
    expected = {'key': 'some_key', 'value': '42'}
    assert expected == result
Esempio n. 11
0
def test_jitted_marshal_method_no_threshold(simple_schema, simple_dict):
    marshal_method = generate_marshall_method(simple_schema, threshold=0)
    assert marshal_method.proxy._call == marshal_method.proxy.no_tracing_call
    result = marshal_method(simple_dict)
    assert simple_dict == result
    assert marshal_method.proxy._call == marshal_method.proxy.no_tracing_call
Esempio n. 12
0
def test_dict_jitted_marshal_method(simple_schema):
    marshal_method = generate_marshall_method(simple_schema)
    result = marshal_method({'key': 'some_key'})
    expected = {'key': 'some_key', 'value': 0}
    assert expected == result
Esempio n. 13
0
def test_jit_bails_nested_attribute():
    class DynamicSchema(Schema):
        foo = fields.String(attribute='foo.bar')

    marshal_method = generate_marshall_method(DynamicSchema())
    assert marshal_method is None