Skip to content

Commit

Permalink
Test single dispatch with entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
deltamarnix committed Oct 7, 2024
1 parent 83602f6 commit 3f4d8d7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
Empty file.
8 changes: 8 additions & 0 deletions flopy4/singledispatch/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from functools import singledispatch


@singledispatch
def plot(obj, **kwargs):
raise NotImplementedError(
"plot method not implemented for type {}".format(type(obj))
)
6 changes: 6 additions & 0 deletions flopy4/singledispatch/plot_int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flopy4.singledispatch.plot import plot


@plot.register
def _(v: int, **kwargs):
print(f"Plotting a model with kwargs: {kwargs}")
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ ignore = [
"E722", # do not use bare `except`
"E741", # ambiguous variable name
]

[project.entry-points.flopy4]
plot = "flopy4.singledispatch.plot_int"
12 changes: 12 additions & 0 deletions test/test_singledispatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from importlib.metadata import entry_points

from flopy4.singledispatch.plot import plot


def test_register_singledispatch_with_entrypoints():
eps = entry_points(group="flopy4", name="plot")
for ep in eps:
_ = ep.load()

# should not throw an error, because plot_int was loaded via entry points
plot(5)

0 comments on commit 3f4d8d7

Please sign in to comment.