-
Notifications
You must be signed in to change notification settings - Fork 137
Add support for anonymous functions to assert_connected #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…string identifiers, allowing callables to be anonymous
bitwes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. These signal asserts are very unwieldy, and this is a good patch to get the new assert functionality.
Just a minor change to not replicate the ugliness of SignalAssertParameters.others. Changing _get_connection_info to return a dictionary might help refactoring that class later too (it needs it).
| return true | ||
| return false | ||
| push_error("Signal connection assertion called with bad signature. Read Docstring for correct signature.") | ||
| return [connected, signal_name, method_name, signal_object_name, method_object_name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a dictionary, an array is too fragile.
| var conn_result = _get_connection_info(p1, p2, p3, p4) | ||
| var connected = conn_result[0] | ||
| var signal_name = conn_result[1] | ||
| var method_name = conn_result[2] | ||
| var signal_object_name = conn_result[3] | ||
| var method_object_name = conn_result[4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing _get_connection_info to return a dictionary means we can use the dictionary values directly.
| var conn_result = _get_connection_info(p1, p2, p3, p4) | ||
| var connected = conn_result[0] | ||
| var signal_name = conn_result[1] | ||
| var method_name = conn_result[2] | ||
| var signal_object_name = conn_result[3] | ||
| var method_object_name = conn_result[4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as assert_connected.
Resolves #786
Previously anonymous functions could not be tested for connection in assert_connected and assert_not_connected. The connection assertions relied on using the names of methods instead of references to them, which gets a little messy with anonymous function because they are all just named "<anonymous function>" (or something similar, I don't remember exactly what).
This PR implements a new system for testing signal/method connection that stores references to methods instead of just their names (and adds tests to make sure this behavior is well documented). The signature of the assertion methods was also a little bit complicated and untyped, and so I took the liberty of adding a push_error informing the user they have incorrectly called the assertion method in the case that they have. I can certainly remove this part if it is found unnecessary.