コード例 #1
0
ファイル: test_fields.py プロジェクト: swistakm/graceful
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'
コード例 #2
0
ファイル: test_fields.py プロジェクト: moolighty/graceful
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'
コード例 #3
0
ファイル: test_fields.py プロジェクト: swistakm/graceful
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')
コード例 #4
0
ファイル: test_fields.py プロジェクト: moolighty/graceful
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')