Skip to content
Myr

Add test to ensure click does not import too much

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent da0a164 · Browse files · 1 file+49 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+49 added−0 removed

  • tests:+49 added−0 removed

1 file+49 added−0 removed

added:tests/test_imports.py+49 added
1import sys2import json3import subprocess456IMPORT_TEST = b'''\7try:8 import __builtin__ as builtins9except ImportError:10 import builtins1112found_imports = set()13real_import = builtins.__import__14import sys1516def tracking_import(module, locals=None, globals=None, fromlist=None,17 level=0):18 rv = real_import(module, locals, globals, fromlist, level)19 if globals and globals['__name__'].startswith('click') and level == 0:20 found_imports.add(module)21 return rv22builtins.__import__ = tracking_import2324import click25rv = list(found_imports)26import json27click.echo(json.dumps(rv))28'''2930ALLOWED_IMPORTS = set([31 'weakref', 'os', 'struct', 'collections', 'sys', 'contextlib',32 'functools', 'stat', 're', 'codecs', 'inspect', 'itertools', 'io'33])343536def test_light_imports():37 c = subprocess.Popen([sys.executable, '-'], stdin=subprocess.PIPE,38 stdout=subprocess.PIPE)39 rv = c.communicate(IMPORT_TEST)[0]4041 if sys.version_info[0] != 2:42 rv = rv.decode('utf-8')43 imported = json.loads(rv)44 print(imported)4546 for module in imported:47 if module == 'click' or module.startswith('click.'):48 continue49 assert module in ALLOWED_IMPORTS