Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
repr(Boolean(input))
assert Boolean(0) == Boolean(False)
assert Boolean(0) != Boolean(True)
assert Boolean(1) == Boolean(True)
assert Boolean(1) != Boolean(False)
assert Boolean("0") == Boolean(False)
assert Boolean("1") == Boolean(True)
assert not Boolean("2").check().ok()
assert Boolean(123).check().ok()
assert Boolean('true').check().ok()
assert Boolean('false').check().ok()
assert Boolean(True).check().ok()
assert Boolean(False).check().ok()
assert not Boolean('{{foo}}').check().ok()
assert Boolean('{{foo}}').bind(foo=True).check().ok()
for input in bad_inputs:
with pytest.raises(SimpleObject.CoercionError):
str(Boolean(input))
with pytest.raises(SimpleObject.CoercionError):
repr(Boolean(input))
for input in good_inputs:
str(Boolean(input))
repr(Boolean(input))
assert Boolean(0) == Boolean(False)
assert Boolean(0) != Boolean(True)
assert Boolean(1) == Boolean(True)
assert Boolean(1) != Boolean(False)
assert Boolean("0") == Boolean(False)
assert Boolean("1") == Boolean(True)
assert not Boolean("2").check().ok()
assert Boolean(123).check().ok()
assert Boolean('true').check().ok()
assert Boolean('false').check().ok()
assert Boolean(True).check().ok()
assert Boolean(False).check().ok()
assert not Boolean('{{foo}}').check().ok()
assert Boolean('{{foo}}').bind(foo=True).check().ok()
def test_boolean_constructors():
bad_inputs = ['', 'a b c', unicodey('a b c'), unicodey(''), '1e5', ' 0']
good_inputs = [unicodey('{{foo}}'), -1, 0, 1, 2, 'true', 'false', '0', '1', True, False]
for input in bad_inputs:
with pytest.raises(SimpleObject.CoercionError):
str(Boolean(input))
with pytest.raises(SimpleObject.CoercionError):
repr(Boolean(input))
for input in good_inputs:
str(Boolean(input))
repr(Boolean(input))
assert Boolean(0) == Boolean(False)
assert Boolean(0) != Boolean(True)
assert Boolean(1) == Boolean(True)
assert Boolean(1) != Boolean(False)
assert Boolean("0") == Boolean(False)
assert Boolean("1") == Boolean(True)
assert not Boolean("2").check().ok()
assert Boolean(123).check().ok()
assert Boolean('true').check().ok()
assert Boolean('false').check().ok()
assert Boolean(True).check().ok()
assert Boolean(False).check().ok()
assert not Boolean('{{foo}}').check().ok()
assert Boolean('{{foo}}').bind(foo=True).check().ok()
def test_bad_inputs():
for typ in Float, Integer, String, Boolean:
with pytest.raises(TypeError):
typ()
with pytest.raises(TypeError):
typ("1", "2")
with pytest.raises(TypeError):
typ(foo = '123')
bad_inputs = [ {1:2}, None, type, Float, Integer, String, Boolean,
Float(1), Integer(1), String(1), Boolean(1) ]
for inp in bad_inputs:
with pytest.raises(SimpleObject.CoercionError):
'%s' % typ(inp)
def test_bad_inputs():
for typ in Float, Integer, String, Boolean:
with pytest.raises(TypeError):
typ()
with pytest.raises(TypeError):
typ("1", "2")
with pytest.raises(TypeError):
typ(foo = '123')
bad_inputs = [ {1:2}, None, type, Float, Integer, String, Boolean,
Float(1), Integer(1), String(1), Boolean(1) ]
for inp in bad_inputs:
with pytest.raises(SimpleObject.CoercionError):
'%s' % typ(inp)
for input in bad_inputs:
with pytest.raises(SimpleObject.CoercionError):
str(Boolean(input))
with pytest.raises(SimpleObject.CoercionError):
repr(Boolean(input))
for input in good_inputs:
str(Boolean(input))
repr(Boolean(input))
assert Boolean(0) == Boolean(False)
assert Boolean(0) != Boolean(True)
assert Boolean(1) == Boolean(True)
assert Boolean(1) != Boolean(False)
assert Boolean("0") == Boolean(False)
assert Boolean("1") == Boolean(True)
assert not Boolean("2").check().ok()
assert Boolean(123).check().ok()
assert Boolean('true').check().ok()
assert Boolean('false').check().ok()
assert Boolean(True).check().ok()
assert Boolean(False).check().ok()
assert not Boolean('{{foo}}').check().ok()
assert Boolean('{{foo}}').bind(foo=True).check().ok()
with pytest.raises(SimpleObject.CoercionError):
repr(Boolean(input))
for input in good_inputs:
str(Boolean(input))
repr(Boolean(input))
assert Boolean(0) == Boolean(False)
assert Boolean(0) != Boolean(True)
assert Boolean(1) == Boolean(True)
assert Boolean(1) != Boolean(False)
assert Boolean("0") == Boolean(False)
assert Boolean("1") == Boolean(True)
assert not Boolean("2").check().ok()
assert Boolean(123).check().ok()
assert Boolean('true').check().ok()
assert Boolean('false').check().ok()
assert Boolean(True).check().ok()
assert Boolean(False).check().ok()
assert not Boolean('{{foo}}').check().ok()
assert Boolean('{{foo}}').bind(foo=True).check().ok()
str(Boolean(input))
with pytest.raises(SimpleObject.CoercionError):
repr(Boolean(input))
for input in good_inputs:
str(Boolean(input))
repr(Boolean(input))
assert Boolean(0) == Boolean(False)
assert Boolean(0) != Boolean(True)
assert Boolean(1) == Boolean(True)
assert Boolean(1) != Boolean(False)
assert Boolean("0") == Boolean(False)
assert Boolean("1") == Boolean(True)
assert not Boolean("2").check().ok()
assert Boolean(123).check().ok()
assert Boolean('true').check().ok()
assert Boolean('false').check().ok()
assert Boolean(True).check().ok()
assert Boolean(False).check().ok()
assert not Boolean('{{foo}}').check().ok()
assert Boolean('{{foo}}').bind(foo=True).check().ok()
def test_boolean_constructors():
bad_inputs = ['', 'a b c', unicodey('a b c'), unicodey(''), '1e5', ' 0']
good_inputs = [unicodey('{{foo}}'), -1, 0, 1, 2, 'true', 'false', '0', '1', True, False]
for input in bad_inputs:
with pytest.raises(SimpleObject.CoercionError):
str(Boolean(input))
with pytest.raises(SimpleObject.CoercionError):
repr(Boolean(input))
for input in good_inputs:
str(Boolean(input))
repr(Boolean(input))
assert Boolean(0) == Boolean(False)
assert Boolean(0) != Boolean(True)
assert Boolean(1) == Boolean(True)
assert Boolean(1) != Boolean(False)
assert Boolean("0") == Boolean(False)
assert Boolean("1") == Boolean(True)
assert not Boolean("2").check().ok()
assert Boolean(123).check().ok()
assert Boolean('true').check().ok()
assert Boolean('false').check().ok()
assert Boolean(True).check().ok()
assert Boolean(False).check().ok()
assert not Boolean('{{foo}}').check().ok()
assert Boolean('{{foo}}').bind(foo=True).check().ok()
def checker(cls, obj):
assert isinstance(obj, Boolean)
if isinstance(obj._value, bool):
return TypeCheck.success()
else:
return TypeCheck.failure("%s not a boolean" % repr(obj._value))