Beispiel #1
0
def test_serialiser_toml(make_dist):
    make_dist()
    jdist = JohnnyDist("jdtest")
    assert jdist.serialise(format="toml") == dedent("""\
        name = "jdtest"
        summary = "default text for metadata summary"
        """)
Beispiel #2
0
def test_serialiser_python(make_dist):
    make_dist()
    jdist = JohnnyDist("jdtest")
    assert jdist.serialise() == [{
        "name": "jdtest",
        "summary": "default text for metadata summary"
    }]
Beispiel #3
0
def main():
    default_fields = os.environ.get("JOHNNYDEP_FIELDS", "name,summary").split(",")
    parser = ArgumentParser()
    parser.add_argument("req", help="The project name or requirement specifier")
    parser.add_argument("--index-url", "-i")
    parser.add_argument(
        "--output-format",
        "-o",
        choices=["human", "json", "yaml", "python", "toml", "pinned"],
        default="human",
    )
    parser.add_argument(
        "--no-deps", help="Don't recurse the dependency tree", dest="recurse", action="store_false"
    )
    parser.add_argument(
        "--fields", "-f", nargs="*", default=default_fields, choices=list(FIELDS) + ["ALL"]
    )
    parser.add_argument("--for-python", "-p", dest="env", type=python_interpreter)
    parser.add_argument("--verbose", "-v", default=1, type=int, choices=range(3))
    args = parser.parse_args()
    if "ALL" in args.fields:
        args.fields = list(FIELDS)
    configure_logging(verbosity=args.verbose)
    dist = JohnnyDist(args.req, index_url=args.index_url, env=args.env)
    print(dist.serialise(fields=args.fields, format=args.output_format, recurse=args.recurse))
Beispiel #4
0
def test_extras_parsing(make_dist, mocker):
    make_dist(name="parent",
              install_requires=['child; extra == "foo" or extra == "bar"'])
    make_dist(name="child")
    assert JohnnyDist("parent").requires == []
    assert JohnnyDist("parent[foo]").requires == ["child"]
    assert JohnnyDist("parent[bar]").requires == ["child"]
    assert JohnnyDist("parent[baz]").requires == []
    assert JohnnyDist("parent[baz,foo]").requires == ["child"]
Beispiel #5
0
def test_serialiser_json(make_dist):
    make_dist()
    jdist = JohnnyDist("jdtest")
    assert jdist.serialise(format="json") == dedent("""\
        [
          {
            "name": "jdtest",
            "summary": "default text for metadata summary"
          }
        ]""")
Beispiel #6
0
def test_serialiser_with_deps():
    dist = JohnnyDist('fakedist[dev]')
    assert dist.serialise(fields=['name']) == [
        {
            'name': 'fakedist'
        },
        {
            'name': 'wheel'
        },
    ]
Beispiel #7
0
def test_serialiser_custom_fields(make_dist):
    make_dist(version="0.1")
    make_dist(version="0.2")
    jdist = JohnnyDist("jdtest")
    expected = [{
        "versions_available": ["0.1", "0.2"],
        "version_latest": "0.2"
    }]
    assert jdist.serialise(fields=("versions_available",
                                   "version_latest")) == expected
Beispiel #8
0
def test_non_json_metadata():
    # this dist uses old-skool metadata format (plaintext not json)
    dist = JohnnyDist('testpath==0.3.1')
    assert dist.serialise(fields=['name', 'summary', 'import_names']) == [{
        'name':
        'testpath',
        'summary':
        'Test utilities for code working with files and commands',
        'import_names': ['testpath'],
    }]
Beispiel #9
0
def test_plaintext_whl_metadata(add_to_index):
    # this dist uses an old-skool metadata version 1.2
    sdist_fname = os.path.join(here, "testpath-0.3.1-py2.py3-none-any.whl")
    fragment = "#md5=12728181294cf6f815421081d620c494"
    add_to_index(name="testpath", path=sdist_fname, urlfragment=fragment)
    dist = JohnnyDist("testpath==0.3.1")
    assert dist.serialise(fields=["name", "summary", "import_names", "homepage"]) == [
        {
            "name": "testpath",
            "summary": "Test utilities for code working with files and commands",
            "import_names": ["testpath"],
            "homepage": "https://github.com/jupyter/testpath",
        }
    ]
Beispiel #10
0
def test_pprint(make_dist, mocker):
    mock_printer = mocker.MagicMock()
    make_dist()
    jdist = JohnnyDist("jdtest")
    jdist._repr_pretty_(mock_printer, cycle=False)
    pretty = '<JohnnyDist jdtest at 0x{:x}>'.format(id(jdist))
    mock_printer.text.reset_mock()
    jdist = JohnnyDist("jdtest[a]~=0.1.2")
    jdist._repr_pretty_(mock_printer, cycle=False)
    pretty = '<JohnnyDist jdtest~=0.1.2[a] at 0x{:x}>'.format(id(jdist))
    mock_printer.text.assert_called_once_with(pretty)
    mock_printer.text.reset_mock()
    jdist._repr_pretty_(mock_printer, cycle=True)
    mock_printer.text.assert_called_once_with(repr(jdist))
Beispiel #11
0
def test_pprint(make_dist, mocker):
    mocker.patch("johnnydep.lib.id", return_value=3735928559, create=True)
    mock_printer = mocker.MagicMock()
    make_dist()
    jdist = JohnnyDist("jdtest")
    jdist._repr_pretty_(mock_printer, cycle=False)
    pretty = "<JohnnyDist jdtest at 0xdeadbeef>"
    mock_printer.text.assert_called_once_with(pretty)
    mock_printer.text.reset_mock()
    jdist = JohnnyDist("jdtest[a]~=0.1.2")
    jdist._repr_pretty_(mock_printer, cycle=False)
    pretty = "<JohnnyDist jdtest~=0.1.2[a] at 0xdeadbeef>"
    mock_printer.text.assert_called_once_with(pretty)
    mock_printer.text.reset_mock()
    jdist._repr_pretty_(mock_printer, cycle=True)
    mock_printer.text.assert_called_once_with(repr(jdist))
Beispiel #12
0
def test_index_file_without_checksum_in_urlfragment(add_to_index, mocker):
    whl_fname = os.path.join(here, "vanilla-0.1.2-py2.py3-none-any.whl")
    add_to_index(name="vanilla", path=whl_fname)
    jdist = JohnnyDist("vanilla")
    assert jdist.versions_available == ["0.1.2"]
    mocker.patch("johnnydep.pipper.urlretrieve", return_value=(whl_fname, {}))
    assert jdist.checksum == "md5=8a20520dcb1b7a729b827a2c4d75a0b6"
Beispiel #13
0
def test_cant_pin():
    whl_fname = os.path.join(here, "vanilla-0.1.2-py2.py3-none-any.whl")
    jdist = JohnnyDist(whl_fname)
    with pytest.raises(Exception) as cm:
        jdist.pinned
    assert str(
        cm.value) == "Can not pin because no version available is in spec"
Beispiel #14
0
def test_flatten_dist_with_deps():
    dist = JohnnyDist('fakedist[dev]')
    reqs = list(flatten_deps(dist))
    [dist0, dist1] = reqs
    assert dist0.name == 'fakedist'
    assert dist0 is dist
    assert str(dist1.req) == 'wheel>=0.30.0'
Beispiel #15
0
def test_version_conflict():
    # wheel v0.30.0 is already installed, but v0.29.0 does exist in index
    dist = JohnnyDist('wheel<0.30.0')
    assert dist.version_installed == '0.30.0'
    assert dist.version_latest == '0.30.0'
    assert dist.versions_available == ['0.29.0', '0.30.0']
    assert dist.version_latest_in_spec == '0.29.0'
Beispiel #16
0
def test_version_latest_in_spec_prerelease_out_of_spec(make_dist):
    make_dist(version="0.1")
    make_dist(version="0.2a0")
    with pytest.raises(CalledProcessError) as cm:
        JohnnyDist("jdtest>0.1")
    msg = "DistributionNotFound: No matching distribution found for jdtest>0.1\n"
    assert cm.value.output.decode().endswith(msg)
Beispiel #17
0
def test_version_nonexisting(make_dist):
    # v0.404 does not exist in index
    make_dist()
    with pytest.raises(CalledProcessError) as cm:
        JohnnyDist("jdtest==0.404")
    msg = "DistributionNotFound: No matching distribution found for jdtest==0.404\n"
    assert cm.value.output.decode().endswith(msg)
Beispiel #18
0
def test_diamond_dependency_resolution(make_dist):
    make_dist(name="dist1", install_requires=["dist2a", "dist2b"])
    make_dist(name="dist2a", install_requires=["dist3[y]>0.2"])
    make_dist(name="dist2b", install_requires=["dist3[x,z]<0.4"])
    make_dist(name="dist3", version="0.2")
    make_dist(name="dist3", version="0.3")
    make_dist(name="dist3", version="0.4")
    jdist = JohnnyDist("dist1")
    dist1, dist2a, dist2b, dist3 = flatten_deps(jdist)

    assert dist1 is jdist
    assert dist1.requires == ["dist2a", "dist2b"]
    assert dist1.required_by == []

    assert dist2a.name == "dist2a"
    assert dist2a.requires == ["dist3[y]>0.2"]
    assert dist2a.required_by == ["dist1"]

    assert dist2b.name == "dist2b"
    assert dist2b.requires == ["dist3[x,z]<0.4"]
    assert dist2b.required_by == ["dist1"]

    assert dist3.name == "dist3"
    assert dist3.required_by == ["dist2a", "dist2b"]
    assert dist3.extras_requested == ["x", "y", "z"]  # merged
    assert dist3.versions_available == ["0.2", "0.3", "0.4"]
    assert dist3.version_latest == "0.4"
    assert dist3.version_latest_in_spec == "0.3"
    assert str(dist3.req.specifier) == "<0.4,>0.2"
Beispiel #19
0
def test_conditional_dependency_included_by_extra_but_excluded_by_environment_marker(
        make_dist):
    make_dist(name="parent",
              extras_require={"x": 'child; python_version<"1.0"'})
    make_dist(name="child")
    jdist = JohnnyDist("parent[x]")
    assert jdist.requires == []
Beispiel #20
0
def test_conditional_dependency_excluded_by_environment_marker(make_dist):
    make_dist(name="parent",
              install_requires=["child1", "child2; python_version<'1.0'"])
    make_dist(name="child1")
    make_dist(name="child2")
    jdist = JohnnyDist("parent")
    assert jdist.requires == ["child1"]
Beispiel #21
0
def test_env_data_converted_to_dict(make_dist):
    make_dist()
    env_data = ("pip_version", "18.0"), ("python_executable", sys.executable)
    jdist = JohnnyDist("jdtest", env=env_data)
    assert jdist.env_data == {
        "pip_version": "18.0",
        "python_executable": sys.executable
    }
Beispiel #22
0
def test_flatten_dist_with_deps(make_dist):
    make_dist(name="root", install_requires=["dep"])
    make_dist(name="dep")
    jdist = JohnnyDist("root")
    reqs = list(flatten_deps(jdist))
    [dist0, dist1] = reqs
    assert dist0 is jdist
    assert dist1.name == "dep"
Beispiel #23
0
def test_resolve_unresolvable():
    dist = JohnnyDist('distX')
    data = dist.serialise(recurse=False,
                          fields=['project_name', 'summary', 'requires'])
    assert data == [{
        'project_name': 'distX',
        'summary': 'Dist with unresolvable dependencies',
        'requires':
        ['distC (<=0.1)',
         'distC (>0.2)'],  # this installation requirement can not be resolved
    }]
    gen = flatten_deps(dist)
    assert next(gen) is dist
    with ShouldRaise(
            DistributionNotFound(
                'No matching distribution found for distc<=0.1,>0.2')):
        next(gen)
Beispiel #24
0
def test_scratch_dirs_are_being_cleaned_up(make_dist):
    make_dist()
    jdist = JohnnyDist("jdtest")
    assert not os.path.exists(jdist.dist_path)
    parent = os.path.dirname(jdist.dist_path)
    assert not os.path.exists(parent)
    grandparent = os.path.dirname(parent)
    assert not os.path.exists(grandparent)
Beispiel #25
0
def test_version_in_spec_not_avail(make_dist):
    make_dist(version="1.2.3")
    make_dist(version="2.3.4")
    make_dist(version="3.4.5")
    with pytest.raises(CalledProcessError) as cm:
        JohnnyDist("jdtest>4")
    msg = "DistributionNotFound: No matching distribution found for jdtest>4\n"
    assert cm.value.output.decode().endswith(msg)
Beispiel #26
0
def test_children(make_dist):
    make_dist(name="parent", install_requires=["child"])
    make_dist(name="child")
    jdist = JohnnyDist("parent")
    [child] = jdist.children
    assert isinstance(child, JohnnyDist)
    assert isinstance(jdist.children, tuple)
    assert child.name == "child"
Beispiel #27
0
def test_conditional_dependency_excluded_by_extra(make_dist):
    make_dist(name="parent",
              install_requires=["child1"],
              extras_require={"x": "child2"})
    make_dist(name="child1")
    make_dist(name="child2")
    jdist = JohnnyDist("parent")
    assert jdist.requires == ["child1"]
Beispiel #28
0
def test_requires(make_dist):
    make_dist(name="parent",
              install_requires=["child1", "child3[extra]", "child2<0.5"])
    make_dist(name="child1")
    make_dist(name="child2")
    make_dist(name="child3")
    jdist = JohnnyDist("parent")
    assert jdist.requires == ["child1", "child2<0.5", "child3[extra]"]
Beispiel #29
0
def test_checksum_md5(make_dist):
    # the actual checksum value is not repeatable because of timestamps, file modes etc
    # so we just assert that we get a value which looks like a valid checkum
    make_dist()
    jdist = JohnnyDist("jdtest")
    hashtype, sep, hashval = jdist.checksum.partition("=")
    assert hashtype == "md5"
    assert sep == "="
    assert len(hashval) == 32
    assert set(hashval) <= set("1234567890abcdef")
Beispiel #30
0
def test_conditional_dependency_included_by_environment_marker_old(make_dist):
    make_dist(
        name="parent",
        install_requires=["child1"],
        extras_require={":python_version>='1.0'": ["child2"]},
    )
    make_dist(name="child1")
    make_dist(name="child2")
    jdist = JohnnyDist("parent")
    assert jdist.requires == ["child1", "child2"]