Adding best practices and assertion checks to workflow_lint#1213
Adding best practices and assertion checks to workflow_lint#1213mvdbeek merged 4 commits intogalaxyproject:masterfrom
Conversation
| return test_valid | ||
|
|
||
|
|
||
| def _check_test_assertions(lint_context, assertion_definitions): |
There was a problem hiding this comment.
maybe this can be improved, if someone knows more about importing Python functions than me?
49bda50 to
2fe2f6b
Compare
2fe2f6b to
7deed56
Compare
planemo/workflow_lint.py
Outdated
| for module in asserts.assertion_modules: | ||
| for function_name in dir(module): | ||
| if function_name.split('assert_')[-1] in assertion_definitions: | ||
| f = module.__dict__[function_name] |
There was a problem hiding this comment.
You could check that this is a function with https://docs.python.org/3/library/inspect.html#inspect.isfunction
and inspect the signature with https://docs.python.org/3/library/inspect.html#inspect.signature instead of relying on TypeError. OTOH that's some manual parsing that is maybe not necessary. A healthy middleground could be to run https://docs.python.org/3/library/inspect.html#inspect.Signature.bind, so we don't have to execute the test function.
There was a problem hiding this comment.
run https://docs.python.org/3/library/inspect.html#inspect.Signature.bind, so we don't have to execute the test function.
That is cool, thanks!
mvdbeek
left a comment
There was a problem hiding this comment.
Really cool, thanks for all the tests!
a81bafa to
8f8c8c4
Compare
| for function_name in dir(module): | ||
| if function_name.split('assert_')[-1] in assertion_definitions: | ||
| signature = inspect.signature(module.__dict__[function_name]) | ||
| try: | ||
| # try mapping the function with the attributes supplied and check for TypeError | ||
| signature.bind('', **assertion_definitions[function_name.split('assert_')[-1]]) | ||
| except AssertionError: | ||
| pass | ||
| except TypeError as e: | ||
| lint_context.error(f'Invalid assertion in tests: {function_name} {str(e)}') | ||
| assertions_valid = False |
There was a problem hiding this comment.
| for function_name in dir(module): | |
| if function_name.split('assert_')[-1] in assertion_definitions: | |
| signature = inspect.signature(module.__dict__[function_name]) | |
| try: | |
| # try mapping the function with the attributes supplied and check for TypeError | |
| signature.bind('', **assertion_definitions[function_name.split('assert_')[-1]]) | |
| except AssertionError: | |
| pass | |
| except TypeError as e: | |
| lint_context.error(f'Invalid assertion in tests: {function_name} {str(e)}') | |
| assertions_valid = False | |
| for function_name, function in asserts.assertion_functions.items(): | |
| if function_name.split('assert_')[-1] in assertion_definitions: | |
| signature = inspect.signature(function) | |
| try: | |
| # try mapping the function with the attributes supplied and check for TypeError | |
| signature.bind('', **assertion_definitions[function_name.split('assert_')[-1]]) | |
| except AssertionError: | |
| pass | |
| except TypeError as e: | |
| lint_context.error(f'Invalid assertion in tests: {function_name} {str(e)}') | |
| assertions_valid = False |
When galaxyproject/galaxy#12528 is incorporated into a published version of galaxy-tool-util this change will be needed.
Fixes #1178, #1181, #1211