Skip to content
Myr

test_imports.py

This file

Path

tests/test_imports.py

55 lines · 1.4 KiB · Python

Last changed by

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

History of this file

Take it

The walk stopped after 200 commits: lines older than 430c50a point at it.

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 1–34why, one step back
1import sys
2import json3import subprocess45from click._compat import WIN678IMPORT_TEST = b'''\9try:10 import __builtin__ as builtins11except ImportError:12 import builtins1314found_imports = set()15real_import = builtins.__import__16import sys1718def tracking_import(module, locals=None, globals=None, fromlist=None,19 level=0):20 rv = real_import(module, locals, globals, fromlist, level)21 if globals and globals['__name__'].startswith('click') and level == 0:22 found_imports.add(module)23 return rv24builtins.__import__ = tracking_import2526import click27rv = list(found_imports)28import json29click.echo(json.dumps(rv))30'''3132ALLOWED_IMPORTS = set([33 'weakref', 'os', 'struct', 'collections', 'sys', 'contextlib',34 'functools', 'stat', 're', 'codecs', 'inspect', 'itertools', 'io',

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 35why, one step back
35 'threading', 'colorama', 'errno', 'fcntl', 'datetime'

Merge pull request #681 from pgkelley4/masterMarkus Unterwaditzerbefore adoption430c50a

lines 36–55why, one step back
36])
3738if WIN:39 ALLOWED_IMPORTS.update(['ctypes', 'ctypes.wintypes', 'msvcrt', 'time',40 'zlib'])414243def test_light_imports():44 c = subprocess.Popen([sys.executable, '-'], stdin=subprocess.PIPE,45 stdout=subprocess.PIPE)46 rv = c.communicate(IMPORT_TEST)[0]4748 if sys.version_info[0] != 2:49 rv = rv.decode('utf-8')50 imported = json.loads(rv)5152 for module in imported:53 if module == 'click' or module.startswith('click.'):54 continue55 assert module in ALLOWED_IMPORTS