Skip to content

Commit

Permalink
Merge pull request #15 from ryanharvey1/add-lazy-loader-test
Browse files Browse the repository at this point in the history
Clean `lazy_loader` from module namespace
  • Loading branch information
ryanharvey1 authored Sep 21, 2024
2 parents c9631d6 + b3e2b25 commit e11cbee
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 33 deletions.
6 changes: 3 additions & 3 deletions neuro_py/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/behavior/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/ensemble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/lfp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/process/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/session/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/spikes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/stats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/tuning/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
41 changes: 41 additions & 0 deletions tests/test_lazy_loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys


def test_lazy_loading():
# clear all neuro_py submodules
for module in list(sys.modules.keys()):
if module.startswith("neuro_py"):
sys.modules.pop(module)

import neuro_py

npy_submodules = set(
x.split(".")[1]
for x in sys.modules.keys()
if (
x.startswith("neuro_py.")
and "__" not in x
and not x.split(".")[1].startswith("_")
and sys.modules[x] is not None
)
)

# ensure that no submodules have been imported yet
assert npy_submodules == set(), \
f"Submodules already loaded: {npy_submodules}"

# ensure that only the accessed submodule has been imported
neuro_py.behavior
npy_submodules = set(
x.split(".")[1]
for x in sys.modules.keys()
if (
x.startswith("neuro_py.")
and "__" not in x
and not x.split(".")[1].startswith("_")
and sys.modules[x] is not None
)
)
assert npy_submodules == {
"behavior"
}, f"Submodules already loaded: {npy_submodules}"

0 comments on commit e11cbee

Please sign in to comment.