-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use
@raises_not_implemented()
instead of raise
statemen…
…ts in `BaseManager` ipython methods (#2069)
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
from ape.utils import ManagerAccessMixin | ||
from ape.utils import ManagerAccessMixin, raises_not_implemented | ||
|
||
|
||
class BaseManager(ManagerAccessMixin): | ||
""" | ||
Base manager that allows us to add other IPython integration features | ||
""" | ||
|
||
@raises_not_implemented | ||
def _repr_mimebundle_(self, include=None, exclude=None): | ||
# This works better than AttributeError for Ape. | ||
raise NotImplementedError("This manager does not implement '_repr_mimebundle_'.") | ||
pass | ||
|
||
@raises_not_implemented | ||
def _ipython_display_(self, include=None, exclude=None): | ||
# This works better than AttributeError for Ape. | ||
raise NotImplementedError("This manager does not implement '_ipython_display_'.") | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
|
||
from ape.exceptions import APINotImplementedError | ||
from ape.managers.base import BaseManager | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def manager(): | ||
class MyManager(BaseManager): | ||
pass | ||
|
||
return MyManager() | ||
|
||
|
||
@pytest.mark.parametrize("fn_name", ("_repr_mimebundle_", "_ipython_display_")) | ||
def test_ipython_integration_defaults(manager, fn_name): | ||
""" | ||
Test default behavior for IPython integration methods. | ||
The base-manager short-circuits to NotImplementedError to avoid | ||
dealing with any custom `__getattr__` logic entirely. This prevents | ||
side-effects such as unnecessary compiling in the ProjectManager. | ||
""" | ||
with pytest.raises(APINotImplementedError): | ||
fn = getattr(manager, fn_name) | ||
fn() |