How to use the pystachio.basic.Boolean function in pystachio

To help you get started, we’ve selected a few pystachio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wickman / pystachio / tests / test_basic_types.py View on Github external
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()
github wickman / pystachio / tests / test_basic_types.py View on Github external
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()
github wickman / pystachio / tests / test_basic_types.py View on Github external
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()
github wickman / pystachio / tests / test_basic_types.py View on Github external
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)
github wickman / pystachio / tests / test_basic_types.py View on Github external
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)
github wickman / pystachio / tests / test_basic_types.py View on Github external
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()
github wickman / pystachio / tests / test_basic_types.py View on Github external
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()
github wickman / pystachio / tests / test_basic_types.py View on Github external
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()
github wickman / pystachio / tests / test_basic_types.py View on Github external
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()
github wickman / pystachio / pystachio / basic.py View on Github external
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))