Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_main_show_only_and_exclude_fails(monkeypatch):
parser = get_parser()
args = parser.parse_args('--packages Flask --exclude Jinja2,Flask'.split())
def _get_args():
return args
monkeypatch.setattr('pipdeptree._get_args', _get_args)
with pytest.raises(SystemExit):
main()
def test_main_show_only_and_exclude_ok(monkeypatch):
parser = get_parser()
args = parser.parse_args('--packages Flask --exclude Jinja2'.split())
def _get_args():
return args
monkeypatch.setattr('pipdeptree._get_args', _get_args)
assert main() == 0
def test_render_tree_freeze_cyclic_dependency():
cyclic_pkgs, dist_index, tree = venv_fixture('tests/virtualenvs/cyclicenv.pickle')
tree_str = render_tree(tree, list_all=True, frozen=True)
lines = set(tree_str.split('\n'))
assert 'CircularDependencyA==0.0.0' in lines
assert ' CircularDependencyB==0.0.0' in lines
assert 'CircularDependencyB==0.0.0' in lines
assert ' CircularDependencyA==0.0.0' in lines
def test_render_tree_cyclic_dependency():
cyclic_pkgs, dist_index, tree = venv_fixture('tests/virtualenvs/cyclicenv.pickle')
tree_str = render_tree(tree, list_all=True)
lines = set(tree_str.split('\n'))
assert 'CircularDependencyA==0.0.0' in lines
assert ' - CircularDependencyB [required: Any, installed: 0.0.0]' in lines
assert 'CircularDependencyB==0.0.0' in lines
assert ' - CircularDependencyA [required: Any, installed: 0.0.0]' in lines
def test_render_tree_freeze():
tree_str = render_tree(tree, list_all=False, frozen=True)
lines = set()
for line in tree_str.split('\n'):
# Workaround for https://github.com/pypa/pip/issues/1867
# When hash randomization is enabled, pip can return different names
# for git editables from run to run
line = line.replace('origin/master', 'master')
line = line.replace('origin/HEAD', 'master')
lines.add(line)
assert 'Flask-Script==2.0.6' in lines
assert ' SQLAlchemy==1.2.9' in lines
# TODO! Fix the following failing test
# assert '-e git+https://github.com/naiquevin/lookupy.git@cdbe30c160e1c29802df75e145ea4ad903c05386#egg=Lookupy-master' in lines
assert 'itsdangerous==0.24' not in lines
def test_render_tree_only_top():
tree_str = render_tree(tree, list_all=False)
lines = set(tree_str.split('\n'))
assert 'Flask-Script==2.0.6' in lines
assert ' - SQLAlchemy [required: >=0.7.6, installed: 1.2.9]' in lines
assert 'Lookupy==0.1' in lines
assert 'itsdangerous==0.24' not in lines
def test_render_tree_list_all():
tree_str = render_tree(tree, list_all=True)
lines = set(tree_str.split('\n'))
assert 'Flask-Script==2.0.6' in lines
assert ' - SQLAlchemy [required: >=0.7.6, installed: 1.2.9]' in lines
assert 'Lookupy==0.1' in lines
assert 'itsdangerous==0.24' in lines
def test_main_show_only_and_exclude_fails(monkeypatch):
parser = get_parser()
args = parser.parse_args('--packages Flask --exclude Jinja2,Flask'.split())
def _get_args():
return args
monkeypatch.setattr('pipdeptree._get_args', _get_args)
with pytest.raises(SystemExit):
main()
def test_main_show_only_and_exclude_ok(monkeypatch):
parser = get_parser()
args = parser.parse_args('--packages Flask --exclude Jinja2'.split())
def _get_args():
return args
monkeypatch.setattr('pipdeptree._get_args', _get_args)
assert main() == 0
def venv_fixture(pickle_file):
"""Loads required virtualenv pkg data from a pickle file
:param pickle_file: path to a .pickle file
:returns: a tuple of pkgs, pkg_index, req_map
:rtype: tuple
"""
with open(pickle_file, 'rb') as f:
pkgs = pickle.load(f)
dist_index = build_dist_index(pkgs)
tree = construct_tree(dist_index)
return pkgs, dist_index, tree