-
Notifications
You must be signed in to change notification settings - Fork 85
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 kwargs to all components #863
Conversation
Codecov Report
@@ Coverage Diff @@
## master #863 +/- ##
=======================================
Coverage 99.69% 99.70%
=======================================
Files 195 195
Lines 7962 8000 +38
=======================================
+ Hits 7938 7976 +38
Misses 24 24
Continue to review full report at Codecov.
|
continue | ||
|
||
obj_class = component._component_obj.__class__.__name__ | ||
module = component._component_obj.__module__ |
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.
@dsherry __module__
was the key!
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.
Amazing!!
@jeremyliweishih is there a reason not to add |
@dsherry I can add it for consistency! It just wasn't actively doing anything in |
for k, v in kwargs.items(): | ||
setattr(self, k, v) | ||
|
||
with patch(patched, new=all_init) as _: |
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.
@jeremyliweishih how come you specified new
here? Why not let patch
set up a MagicMock
automatically?
with patch(patched) as mock_component_obj:
component = component_class(test_arg="test")
assert component.parameters['test_arg'] == "test"
mock_component_obj.assert_called_with(test_arg="test")
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 don't have the exact error statement right now but MagicMock
doesn't work directly with __init__
thus using the new=all_init
. Before I had mocked_obj.__init__ = wtv
and it didn't work.
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.
@jeremyliweishih got it, thanks. Yeah let's add **kwargs
to ComponentBase.__init__
/base class inits for consistency. Also I left a comment on the mocking in the unit test. Other than that LGTM!! Pretty cool that you figured out the dynamic mocking, great to have that pattern in place!
assert component._component_obj.test_arg == "test" | ||
|
||
|
||
def test_component_has_random_state(): |
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.
@dsherry this replaces the check in test_pipelines.py
on if components have random_state
as a parameter.
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.
Awesome. Thanks
fixes #775.