Skip to content

Commit cae5a92

Browse files
committed
Add a test for lazy module loading
1 parent b4880c9 commit cae5a92

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lib/matplotlib/tests/test_basic.py

+38
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import builtins
2+
import subprocess
3+
import sys
24

35
import matplotlib
46

57

8+
69
def test_simple():
710
assert 1 + 1 == 2
811

@@ -34,3 +37,38 @@ def test_override_builtins():
3437

3538
def test_verbose():
3639
assert isinstance(matplotlib.verbose, matplotlib.Verbose)
40+
41+
42+
def test_lazy_imports():
43+
# The list of modules we want to ensure aren't imported by default
44+
lazy_modules = [
45+
'matplotlib._png',
46+
'matplotlib._tri',
47+
'matplotlib._qhull',
48+
'matplotlib._contour'
49+
]
50+
51+
# The list of modules to import that shouldn't import any of the
52+
# lazy_modules
53+
top_level_modules = [
54+
'matplotlib.figure',
55+
'matplotlib.backend_bases',
56+
'matplotlib.pyplot'
57+
]
58+
59+
for top_level_module in top_level_modules:
60+
lines = [
61+
"import sys",
62+
"import {}".format(top_level_module)
63+
]
64+
for lazy_module in lazy_modules:
65+
lines.append('assert {!r} not in sys.modules'.format(lazy_module))
66+
source = '\n'.join(lines)
67+
68+
print(source)
69+
70+
subprocess.check_call([
71+
sys.executable,
72+
'-c',
73+
source
74+
])

0 commit comments

Comments
 (0)