def test_dictionary_decorated(self): @types.dictionary def validate(value): assert len(value) == 1, 'too long' with raises(AssertionError) as exc: validate({'a': 1, 'b': 2}) result = util.assert_message(exc) assert result == 'too long'
def test_array_decorated(self): @types.array def validate(value): assert len(value) == 1, 'too long' with raises(AssertionError) as exc: validate([1, 2]) result = util.assert_message(exc) assert result == 'too long'
def test_string_decorated(self): @types.string def validate(value): assert len(value) == 1, 'too long' with raises(AssertionError) as exc: validate('123') result = util.assert_message(exc) assert result == 'too long'
def test_boolean_decorated(self): @types.boolean def validate(value): assert value is False, 'not false' with raises(AssertionError) as exc: validate(True) result = util.assert_message(exc) assert result == 'not false'
def test_array_decorated(self): @types.array def validate(value): assert len(value) == 1, 'too long' with raises(AssertionError) as exc: validate([1, 2]) result = util.assert_message(exc) assert result == 'too long'
def test_dictionary_decorated(self): @types.dictionary def validate(value): assert len(value) == 1, 'too long' with raises(AssertionError) as exc: validate({'a': 1, 'b': 2}) result = util.assert_message(exc) assert result == 'too long'
def test_boolean_decorated(self): @types.boolean def validate(value): assert value is False, 'not false' with raises(AssertionError) as exc: validate(True) result = util.assert_message(exc) assert result == 'not false'
def test_string_decorated(self): @types.string def validate(value): assert len(value) == 1, 'too long' with raises(AssertionError) as exc: validate('123') result = util.assert_message(exc) assert result == 'too long'
def test_integer_fail(self): @types.integer def validate(value): assert value == 1, 'too big' with raises(AssertionError) as exc: validate(3) result = util.assert_message(exc) assert result == 'too big'
def test_integer_fail(self): @types.integer def validate(value): assert value == 1, 'too big' with raises(AssertionError) as exc: validate(3) result = util.assert_message(exc) assert result == 'too big'
def test_callable_with_messages_are_passed_on(self): def callable_message(v): assert False, "this is completely False" with raises(Invalid) as exc: engine.enforce(1, callable_message, ['1'], 'key') result = util.assert_message(exc.value.reason) assert result == "this is completely False"