Exemplo n.º 1
0
def test_spawn():
    desc = 'foo'
    f = Field(description=desc)
    f1 = f.spawn(required=True)

    # test spawn attributes are changed
    assert f.required is False
    assert f1.required is True
    assert f.description == f1.description

    # test spawn instances do not share key attr
    assert f.key is None

    class P0(ParamSet):
        key0 = f

    assert f.key == 'key0'

    class P1(ParamSet):
        key1 = f.spawn(null=True)

    assert f.key == 'key0'

    f.spawn(key='key2')
    assert f.key == 'key0'
Exemplo n.º 2
0
def test_spawn():
    desc = 'foo'
    f = Field(description=desc)
    f1 = f.spawn(required=True)

    assert f.required is False
    assert f1.required is True
    assert f.description == f1.description
Exemplo n.º 3
0
def test_field_null_values():
    f0 = Field(null_values=(None, 0), null=True)

    assert None is f0.validate(None)
    assert None is f0.validate(0)
    assert '' == f0.validate('')

    f1 = f0.spawn(null=False)
    with pytest.raises(ValueError):
        f1.validate(None)
    with pytest.raises(ValueError):
        f1.validate(0)
    assert '' == f0.validate('')

    # though null is not allowed, value will never be determined as null, so `null=False` won't take any effect
    f2 = Field(null_values=(), null=False)
    assert None is f2.validate(None)