Skip to content
Myr

test_imports.py

This file

Path

tests/test_imports.py

56 lines · 1.4 KiB · Python

Last changed by

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption702acf7

History of this file

Take it

The walk stopped after 200 commits: lines older than 1318a20 point at it.

Added test for open_fileArmin Ronacherbefore adoption1318a20

lines 1–4why, one step back
1import sys
2import json3import subprocess4

Fixed broken tests and behavior on windows.Armin Ronacherbefore adoption262c275

line 5why, one step back
5from click._compat import WIN

Added test for open_fileArmin Ronacherbefore adoption1318a20

line 6why, one step back
6

Fixed broken tests and behavior on windows.Armin Ronacherbefore adoption262c275

line 7why, one step back
7

Added test for open_fileArmin Ronacherbefore adoption1318a20

lines 8–33why, one step back
8IMPORT_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',

Merge pull request #379 from mitsuhiko/feature/global-ctxArmin Ronacherbefore adoption022fc73

line 34why, one step back
34 'functools', 'stat', 're', 'codecs', 'inspect', 'itertools', 'io',

Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption702acf7

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

Added test for open_fileArmin Ronacherbefore adoption1318a20

line 36why, one step back
36])

Fixed broken tests and behavior on windows.Armin Ronacherbefore adoption262c275

lines 37–38why, one step back
37
38if WIN:

Added time as allowed import on windowsArmin Ronacherbefore adoption64c4567

lines 39–40why, one step back
39 ALLOWED_IMPORTS.update(['ctypes', 'ctypes.wintypes', 'msvcrt', 'time',
40 'zlib'])

Added test for open_fileArmin Ronacherbefore adoption1318a20

lines 41–56why, one step back
41
4243def 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)51 print(imported)5253 for module in imported:54 if module == 'click' or module.startswith('click.'):55 continue56 assert module in ALLOWED_IMPORTS