Beispiel #1
0
def test_render_json_tree():
    output = render_json_tree(tree, indent=4)
    data = json.loads(output)

    # @TODO: This test fails on travis because gnureadline doesn't
    # appear as a dependency of ipython (which it is)
    #
    # ignored_pkgs = {'pip', 'pipdeptree', 'setuptools', 'wheel'}
    # pkg_keys = set([d['key'].lower() for d in data
    #                 if d['key'].lower() not in ignored_pkgs])
    # expected = {'alembic', 'flask-script', 'ipython',
    #             'lookupy', 'psycopg2', 'redis', 'slugify'}
    # assert pkg_keys - expected == set()

    matching_pkgs = [p for p in data if p['key'] == 'flask-script']
    assert matching_pkgs
    flask_script = matching_pkgs[0]

    matching_pkgs = [
        p for p in flask_script['dependencies'] if p['key'] == 'flask'
    ]
    assert matching_pkgs
    flask = matching_pkgs[0]

    matching_pkgs = [p for p in flask['dependencies'] if p['key'] == 'jinja2']
    assert matching_pkgs
    jinja2 = matching_pkgs[0]

    assert [p for p in jinja2['dependencies'] if p['key'] == 'markupsafe']
def test_render_json_tree():
    output = render_json_tree(tree, indent=4)
    data = json.loads(output)

    # @TODO: This test fails on travis because gnureadline doesn't
    # appear as a dependency of ipython (which it is)
    #
    # ignored_pkgs = {'pip', 'pipdeptree', 'setuptools', 'wheel'}
    # pkg_keys = set([d['key'].lower() for d in data
    #                 if d['key'].lower() not in ignored_pkgs])
    # expected = {'alembic', 'flask-script', 'ipython',
    #             'lookupy', 'psycopg2', 'redis', 'slugify'}
    # assert pkg_keys - expected == set()

    matching_pkgs = [p for p in data if p['key'] == 'flask-script']
    assert matching_pkgs
    flask_script = matching_pkgs[0]

    matching_pkgs = [p for p in flask_script['dependencies'] if p['key'] == 'flask']
    assert matching_pkgs
    flask = matching_pkgs[0]

    matching_pkgs = [p for p in flask['dependencies'] if p['key'] == 'jinja2']
    assert matching_pkgs
    jinja2 = matching_pkgs[0]

    assert [p for p in jinja2['dependencies'] if p['key'] == 'markupsafe']
Beispiel #3
0
def test_render_json_tree():
    output = render_json_tree(tree, indent=4)
    data = json.loads(output)
    assert 9 == len(data)

    matching_pkgs = [p for p in data if p['key'] == 'flask-script']
    assert matching_pkgs
    flask_script = matching_pkgs[0]

    matching_pkgs = [p for p in flask_script['dependencies'] if p['key'] == 'flask']
    assert matching_pkgs
    flask = matching_pkgs[0]

    matching_pkgs = [p for p in flask['dependencies'] if p['key'] == 'jinja2']
    assert matching_pkgs
    jinja2 = matching_pkgs[0]

    assert [p for p in jinja2['dependencies'] if p['key'] == 'markupsafe']
Beispiel #4
0
import pipdeptree
import json

pkgs = pipdeptree.get_installed_distributions()
dist_index = pipdeptree.build_dist_index(pkgs)
tree = pipdeptree.construct_tree(dist_index)
json_tree = json.loads(pipdeptree.render_json_tree(tree, indent=0))
print(json_tree)
print([
    package for package in json_tree if package['package_name'] == 'tornado'
][0])