diff --git a/src/ape/managers/base.py b/src/ape/managers/base.py index d485e6d2b9..75371dd980 100644 --- a/src/ape/managers/base.py +++ b/src/ape/managers/base.py @@ -1,4 +1,4 @@ -from ape.utils import ManagerAccessMixin +from ape.utils import ManagerAccessMixin, raises_not_implemented class BaseManager(ManagerAccessMixin): @@ -6,10 +6,12 @@ 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 diff --git a/tests/functional/test_base_manager.py b/tests/functional/test_base_manager.py new file mode 100644 index 0000000000..67e438bc66 --- /dev/null +++ b/tests/functional/test_base_manager.py @@ -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()