-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context manager support for Services (#554)
Work towards making the setup/teardown work for the SshService managed by a Context instead of global. To do this, we introspect all of the methods registered for a Service mixin (which we also renamed from `self._services` to `self._service_methods`), and pull out their unique Service instance references from the `__self__` attribute in the bound method that was registered, then store them as `self._services`. This is to handle the case where a single method name was overridden multiple times. At this point, we have enough information to invoke a sort of `__enter__` context for each of those Service instances. However, since we use `__enter__` to invoke all of them, we instead need to implement a separate `_enter_context()` method that does the actual work, and can then be overridden by the subclasses. Unfortunately, this technique make tamper with the order the Services were layered on one another, so any logic that required relying on that order for context setup might be problematic. I don't know if that will actually be an issue, so for now, I'm ignoring the issue and just documenting it. This PR does not include explicit new tests for this, though does have to fixup a few mocks in order to make sure that we're registered bound methods and not just functions. #510 will add additional tests after this is merged.
- Loading branch information
Showing
3 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters