-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ryanharvey1/add-lazy-loader-test
Clean `lazy_loader` from module namespace
- Loading branch information
Showing
12 changed files
with
74 additions
and
33 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,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 |
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,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 |
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,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 |
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,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 |
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,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 |
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,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 |
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,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 |
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,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 |
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,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 |
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,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 |
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,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 |
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,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}" |