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
add typechecking for patched functions args #124
add typechecking for patched functions args #124
Conversation
tests/mock_callable_testslide.py
Outdated
def calling_patched_functions_with_bad_types_raises_TypeError(self): | ||
t = TargetStr() | ||
self.mock_callable(t, "typedfun").to_return_value("This is patched") | ||
with self.assertRaises(TypeError): |
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.
Better use https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaisesRegex here, and assert that the error str matches what we expect. Without it, if there's a TypeError for other reasons (eg: giving more arguments than expected), test will pass, but it won't be actually testing type checking.
testslide/strict_mock.py
Outdated
@@ -10,6 +10,7 @@ | |||
import os.path | |||
|
|||
from unittest.mock import _must_skip | |||
from .lib import _validate_function_signature | |||
|
|||
|
|||
def _add_signature_validation(value, template, attr_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.
s/_add_signature_validation/_wrap_signature_and_type_validation/g
Fair?
This is an amazing feature, I feel like it deserves being added to the documentation here I'd add another section "Type Checking Validation" and give an example, similar to the one for signatures. It is amazing how small this PR is, and how powerful it'll be :-D |
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.
Neat!
No description provided.