-
Notifications
You must be signed in to change notification settings - Fork 56
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 type validation to mock constructor #146
Conversation
5c905e3
to
7bb043d
Compare
@david-caro your #149 fix worked, thanks! |
7bb043d
to
9f1bf7c
Compare
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.
👍
messenger_mock = testslide.StrictMock(template=Messenger) | ||
self.mock_constructor(sys.modules[__name__], "Messenger").to_return_value(messenger_mock) | ||
with self.assertRaises(TypeError): | ||
# TypeError: Call with incompatible argument types: |
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.
nit: indents are weird (2 spaces here, 4 in the block before)
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.
Fixed this on master after the merge, tkz.
if target_class_id in _target_class_id_by_original_class_id: | ||
raise RuntimeError("Can not mock the same class at two different modules!") | ||
else: | ||
_target_class_id_by_original_class_id[id(original_class)] = target_class_id | ||
|
||
original_class_new = original_class.__new__ |
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.
I would have forgotten about new xd
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.
Turns out, it is there only for being future proof, as mock_constructor()
currently can't handle classes that define their own __new__
: #155.
Ditto.
This is currently failing due to #145, tests will likely pass once that's fixed.
Closes #146.
Closes #142.