Ejemplo n.º 1
0
def test_empty_raises():
    with pytest.raises(ValueError):
        mapping()
Ejemplo n.º 2
0
import pytest
from radar_server.fields import mapping, string, integer

foobar_mapping = mapping(foo=string(), bar=integer())


def test_mapping_field_cast():
    foobar = foobar_mapping()('foobar')
    values = foobar({'foobar': {'foo': 1, 'bar': '1'}})
    assert values['foo'] == '1'
    assert values['bar'] == 1


def test_mapping_null():
    foobar = foobar_mapping()('foobar')
    assert foobar({'foobar': None}) is None


def test_mapping_null_raises():
    foobar = foobar_mapping(not_null=True)('foobar')
    with pytest.raises(ValueError):
        foobar({'foobar': None})


def test_mapping_key_raises():
    with pytest.raises(ValueError):
        foobar_mapping(key=True)


def test_mapping_name():
    def resolver(foobar_mapping):
Ejemplo n.º 3
0
def bench_mapping_get_value():
    foobar = fields.mapping(foo=fields.string(), bar=fields.integer())()('foobar')
    Timer(foobar, {'foobar': {'foo': 'bar', 'bar': '3'}}).time(1E5)
Ejemplo n.º 4
0
def bench_mapping_init():
    Timer(fields.mapping(foo=fields.string(), bar=fields.integer())(), 'foobar').time(1E5)
Ejemplo n.º 5
0
def bench_mapping_full_init():
    Timer(lambda: fields.mapping(foo=fields.string(), bar=fields.integer())()('foobar')).time(1E5)