def test_boolean(): codec = Boolean(true="true", false="false", default_value=False) assert codec.encode(True) == 'true' assert codec.encode(False) == 'false' assert codec.decode("true") is True assert codec.decode("false") is False assert codec.decode(None) is False with raises(EncodeError): print(codec.encode("string")) with raises(DecodeError): print(codec.decode("another"))
def test_boolean_tuple(): true = ("true", "on", "yes") false = ("false", "off", "no") codec = Boolean(true=true, false=false, default_value=False) assert codec.encode(True) in true assert codec.encode(False) in false assert codec.decode("on") is True assert codec.decode("no") is False with raises(EncodeError): print(codec.encode(111)) with raises(DecodeError): print(codec.decode("is one true?"))