1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
import sys
from . import version_skip
@version_skip
def test_lazy_imports():
# plotly not imported yet
assert "plotly" not in sys.modules
# Import top-level plotly module
import plotly
assert "plotly" in sys.modules
# Check that submodules are not auto-imported, but can be be accessed using
# attribute syntax
submodules = ["graph_objs", "io"]
for m in submodules:
module_str = "plotly." + m
assert module_str not in sys.modules
getattr(plotly, m)
assert module_str in sys.modules
# Check that constructing and serializing empty figure doesn't auto-import
# nested graph objects
plotly.graph_objects.Figure().to_json()
submodules = [("layout", "title"), ("scatter", "marker"), ("scattergl", "marker")]
for module_parts in submodules:
module_str = "plotly.graph_objs." + ".".join(module_parts)
assert module_str not in sys.modules
# Use getattr to
module = plotly.graph_objects
for m in module_parts:
module = getattr(module, m)
assert module_str in sys.modules
|