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'
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')