Esempio n. 1
0
def test_not_null_passes():
    foo = field(not_null=False)('foo')
    assert foo({'foo': None}) is None
Esempio n. 2
0
def test_default():
    foo = field(default='foo')('foo')
    assert foo({'foo': None}) == 'foo'
Esempio n. 3
0
def test_key():
    foo = field()('foo')
    assert foo.key is False

    foo = field(key=True)('foo')
    assert foo.key is True
Esempio n. 4
0
def test_not_null_raises():
    foo = field(not_null=True)('foo')

    with pytest.raises(ValueError):
        foo({'foo': None})
Esempio n. 5
0
def test_default_resolver_raises():
    foo = field()('foo')

    with pytest.raises(KeyError):
        foo({'bar': '1.2'})
Esempio n. 6
0
def test_default_resolver_context():
    def resolver(state, name, special=None):
        assert special == 'bar'

    foo = field(resolver)('foo')
    foo({'foo': None}, special='bar')
Esempio n. 7
0
def test_name():
    def resolver(state, name):
        assert name == 'foo'

    foo = field(resolver)
    foo('foo')({})
Esempio n. 8
0
def test_cast():
    foo = field(cast=float)('foo')
    assert isinstance(foo({'foo': '1.2'}), float)
Esempio n. 9
0
def bench_field_get_value():
    foo = fields.field()('foo')
    Timer(foo, {'foo': 'bar'}).time(1E5)
Esempio n. 10
0
def bench_field_full_init():
    Timer(lambda: fields.field()('foo')).time(1E5)
Esempio n. 11
0
def bench_field_init():
    Timer(fields.field(), 'foo').time(1E5)