Пример #1
0
def test_not_null_passes():
    foo = field(not_null=False)('foo')
    assert foo({'foo': None}) is None
Пример #2
0
def test_default():
    foo = field(default='foo')('foo')
    assert foo({'foo': None}) == 'foo'
Пример #3
0
def test_key():
    foo = field()('foo')
    assert foo.key is False

    foo = field(key=True)('foo')
    assert foo.key is True
Пример #4
0
def test_not_null_raises():
    foo = field(not_null=True)('foo')

    with pytest.raises(ValueError):
        foo({'foo': None})
Пример #5
0
def test_default_resolver_raises():
    foo = field()('foo')

    with pytest.raises(KeyError):
        foo({'bar': '1.2'})
Пример #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')
Пример #7
0
def test_name():
    def resolver(state, name):
        assert name == 'foo'

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