Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion langex/utils/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle_callable(
) -> None:
if result.evaluated(): return
if args.arg_type != callable: return
return callable(args.received_arg)
result.evaluate(callable(args.received_arg))

def handle_langex_class(
result: _MatchResult, args: _MatchArgs
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "langex"
version = "0.4.4"
version = "0.4.5"
description = "Runtime language extensions and validation tools for Python"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down
90 changes: 90 additions & 0 deletions tests/functions/test_validations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from langex.core.errors import ValidationError
from langex.core.functions import args_required, returns
from langex.core.testing import discover_test, expects

@args_required(int)
def func(arg):
return 0

@args_required(str)
def func2(arg):
return 0

@args_required(float)
def func3(arg):
return 0

@args_required(bool)
def func4(arg):
return 0

@args_required(callable)
def func5(arg):
return 0

@returns(int)
def func6():
return 0

@returns(str)
def func7():
return "0"

@returns(float)
def func8():
return 0.0

@returns(bool)
def func9():
return False

@returns(callable)
def func10():
return lambda: None

@returns(int)
def func11():
return "0"

@returns(str)
def func12():
return 0

@returns(float)
def func13():
return "0"

@returns(bool)
def func14():
return "0"

@returns(callable)
def func15():
return "0"

@discover_test
def test_arg_validations():
(lambda: func(1) ) @expects (0)
(lambda: func2("1") ) @expects (0)
(lambda: func3(0.0) ) @expects (0)
(lambda: func4(True) ) @expects (0)
(lambda: func5(lambda: None)) @expects (0)
(lambda: func("1") ) @expects (ValidationError)
(lambda: func2(1) ) @expects (ValidationError)
(lambda: func3(0) ) @expects (ValidationError)
(lambda: func4(1) ) @expects (ValidationError)
(lambda: func5(1) ) @expects (ValidationError)

@discover_test
def test_return_validations():
(lambda: func6() ) @expects (0)
(lambda: func7() ) @expects ("0")
(lambda: func8() ) @expects (0.0)
(lambda: func9() ) @expects (False)
(lambda: callable(func10())) @expects (True)
(lambda: func11() ) @expects (ValidationError)
(lambda: func12() ) @expects (ValidationError)
(lambda: func13() ) @expects (ValidationError)
(lambda: func14() ) @expects (ValidationError)
(lambda: func15() ) @expects (ValidationError)

Loading