Ejemplo n.º 1
0
def test_write_identical_items():
    class ModelA(props.Model):
        x = props.Int(min_value=5, max_value=10)

    class ModelB(props.Model):
        x = props.Int(min_value=5, max_value=10)

    props.Compound(ModelA, ModelB)
Ejemplo n.º 2
0
def test_fails_to_combine_wrong_types():
    class ModelA(props.Model):
        x = props.Int()

    class ModelB(props.Model):
        x = props.String()

    with pytest.raises(ValueError):
        props.Compound(ModelA, ModelB)
Ejemplo n.º 3
0
def test_fails_to_write_non_identical_items():
    class ModelA(props.Model):
        x = props.Int(min_value=5, max_value=10)

    class ModelB(props.Model):
        x = props.Int(min_value=5, max_value=11)

    with pytest.raises(ValueError):
        props.Compound(ModelA, ModelB)
Ejemplo n.º 4
0
def test_default():
    prop = props.Compound(ModelA, ModelB, default={"x": 1, "y": 2})
    assert prop.load(None) == {"x": 1, "y": 2}
Ejemplo n.º 5
0
def test_not_nullable():
    with pytest.raises(props.PropertyValidationError):
        props.Compound(ModelA, ModelB).load(None)
Ejemplo n.º 6
0
def test_wrong_type():
    with pytest.raises(props.PropertyValidationError):
        props.Compound(ModelA, ModelB).load("12345")
Ejemplo n.º 7
0
def test_combine_invalid_props():
    with pytest.raises(ValueError):
        props.Compound(ModelA, {"x": 123})
Ejemplo n.º 8
0
def test_nullable():
    props.Compound(ModelA, ModelB, nullable=True).load(None)
Ejemplo n.º 9
0
def test_combine_invalid():
    with pytest.raises(ValueError):
        props.Compound(ModelA, 123)
Ejemplo n.º 10
0
def test_combine_nested():
    prop = props.Compound(ModelA, props.Nested(ModelB))
    assert list(prop.__props__.keys()) == ["x", "y"]
Ejemplo n.º 11
0
def test_combine_dict():
    prop = props.Compound(ModelA, {"y": props.Int})
    assert list(prop.__props__.keys()) == ["x", "y"]
Ejemplo n.º 12
0
def test_combine_inline():
    prop = props.Compound(ModelA, props.Inline(props=dict(y=props.Int)))
    assert list(prop.__props__.keys()) == ["x", "y"]
Ejemplo n.º 13
0
def test_combine():
    assert list(props.Compound(ModelA, ModelB).__props__.keys()) == ["x", "y"]