Beispiel #1
0
def test_bool_field_custom_representations():
    field = BoolField("test bool field", representations=('foo', 'bar'))

    assert field.from_representation('foo') is False
    assert field.from_representation('bar') is True

    assert field.to_representation(False) == 'foo'
    assert field.to_representation(True) == 'bar'
Beispiel #2
0
def test_bool_field_custom_representations():
    field = BoolField("test bool field", representations=('foo', 'bar'))

    assert field.from_representation('foo') is False
    assert field.from_representation('bar') is True

    assert field.to_representation(False) == 'foo'
    assert field.to_representation(True) == 'bar'
Beispiel #3
0
def test_bool_field():
    field = BoolField("test bool field")

    # note: this both checks also ensures that accepted representations do
    # not overlap
    for representation in BoolField._FALSE_VALUES:
        assert field.from_representation(representation) is False
    for representation in BoolField._TRUE_VALUES:
        assert field.from_representation(representation) is True

    assert field.to_representation(True) is True
    assert field.to_representation(False) is False

    with pytest.raises(ValueError):
        field.from_representation('foobar')
Beispiel #4
0
def test_bool_field():
    field = BoolField("test bool field")

    # note: this both checks also ensures that accepted representations do
    # not overlap
    for representation in BoolField._FALSE_VALUES:
        assert field.from_representation(representation) is False
    for representation in BoolField._TRUE_VALUES:
        assert field.from_representation(representation) is True

    assert field.to_representation(True) is True
    assert field.to_representation(False) is False

    with pytest.raises(ValueError):
        field.from_representation('foobar')