Skip to content

Commit

Permalink
Cover missing branches of get_module_funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCEllis committed Nov 6, 2023
1 parent f36242d commit e703086
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tests/example_modules/ex_othermod/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from ducktools.lazyimporter import (
LazyImporter,
FromImport,
get_module_funcs,
)

name = "ex_othermod"

laz = LazyImporter(
[FromImport("..ex_mod.ex_submod", "name")],
[FromImport("..ex_mod.ex_submod", "name", "submod_name")],
globs=globals(),
)

__getattr__, __dir__ = get_module_funcs(laz, module_name=__name__)
2 changes: 1 addition & 1 deletion tests/test_basic_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ def test_relative_import(self):
def test_submod_relative_import(self):
from example_modules.ex_othermod import laz

assert laz.name == "ex_submod"
assert laz.submod_name == "ex_submod"
11 changes: 11 additions & 0 deletions tests/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ def test_dir_func(self):
_, dir_func = get_module_funcs(laz)

assert dir_func() == ["collections"]

def test_getattr_module_func(self):
import example_modules.ex_othermod as ex_othermod # noqa # pyright: ignore

assert ex_othermod.submod_name == "ex_submod"

def test_dir_module_func(self):
import example_modules.ex_othermod as ex_othermod # noqa # pyright: ignore

assert "name" in dir(ex_othermod)
assert "submod_name" in dir(ex_othermod)

0 comments on commit e703086

Please sign in to comment.