Ejemplo n.º 1
0
def test_no_candidate_found_no_versions():
    ireq = install_req_from_line('some-package==12.3.4')
    tried = []
    no_candidate_found = NoCandidateFound(ireq, tried, get_finder())
    assert '{}'.format(no_candidate_found) == (
        "Could not find a version that matches some-package==12.3.4\n"
        "No versions found\n"
        "Was pypi.localhost reachable?")
Ejemplo n.º 2
0
def test_unsupported_constraint_editable_wheel():
    wheel_path = os.path.join(
        FAKE_PYPI_WHEELS_DIR, 'small_fake_a-0.1-py2.py3-none-any.whl')
    msg = "Editable wheel is too square"
    ireq_wheel = install_req_from_line(wheel_path)
    ireq = install_req_from_editable(str(ireq_wheel.link))
    unsupported_constraint = UnsupportedConstraint(msg, ireq)
    assert '{}'.format(unsupported_constraint) == (
        "Editable wheel is too square (constraint was: {})".format(ireq))
Ejemplo n.º 3
0
def test_no_candidate_found_with_versions():
    ireq = install_req_from_line('some-package==12.3.4')
    tried = [
        InstallationCandidate('some-package', ver, None)
        for ver in ['1.2.3', '12.3.0', '12.3.5']]
    no_candidate_found = NoCandidateFound(ireq, tried, get_finder())
    assert '{}'.format(no_candidate_found) == (
        "Could not find a version that matches some-package==12.3.4\n"
        "Tried: 1.2.3, 12.3.0, 12.3.5\n"
        "There are incompatible versions in the resolved dependencies.")
Ejemplo n.º 4
0
    def _get_dependencies(self, ireq):
        if ireq.editable:
            return self.editables[str(ireq.link)]

        name, version, extras = as_tuple(ireq)
        # Store non-extra dependencies under the empty string
        extras += ("", )
        dependencies = [
            dep for extra in extras for dep in self.index[name][version][extra]
        ]
        return [
            install_req_from_line(dep, constraint=ireq.constraint)
            for dep in dependencies
        ]
Ejemplo n.º 5
0
def test_pypirepo_calls_reqset_with_str_paths():
    """
    Make sure that paths passed to RequirementSet init are str.

    Passing unicode paths on Python 2 could make pip fail later on
    unpack, if the package contains non-ASCII file names, because
    non-ASCII str and unicode paths cannot be combined.
    """
    with patch('prequ.repositories.pypi.RequirementSet') as mocked_init:
        repo = get_pypi_repository()
        ireq = install_req_from_line('ansible==2.4.0.0')

        # Setup a mock object to be returned from the RequirementSet call
        mocked_reqset = MagicMock()
        mocked_init.return_value = mocked_reqset

        # Fill link for ireq, because get_dependencies uses it as a cache key
        ireq.link = MagicMock(url='http://localhost/ansible2400.zip')

        # Do the call
        repo.get_dependencies(ireq)

        # Check that RequirementSet init is called with correct type arguments
        assert mocked_init.call_count == 1
        (init_call_args, init_call_kwargs) = mocked_init.call_args
        assert isinstance(init_call_args[0], str)
        assert isinstance(init_call_args[1], str)
        assert isinstance(init_call_kwargs.get('download_dir'), str)
        assert isinstance(init_call_kwargs.get('wheel_download_dir'), str)

        # Check that _prepare_file is called correctly
        assert mocked_reqset._prepare_file.call_count == 1
        (pf_call_args, pf_call_kwargs) = mocked_reqset._prepare_file.call_args
        (called_with_finder, called_with_ireq) = pf_call_args
        assert isinstance(called_with_finder, PackageFinder)
        assert called_with_ireq == ireq
        assert not pf_call_kwargs
Ejemplo n.º 6
0
def test_pypirepo_calls_preparer_with_str_paths(mocked_init, mocked_resolver,
                                                mocked_reqset):
    """
    Make sure that paths passed to RequirementPreparer init are str.

    Similar to `test_pypirepo_calls_reqset_with_str_paths` but for Pip 10.
    """
    repo = get_pypi_repository()
    ireq = install_req_from_line('ansible==2.4.0.0')
    ireq.link = MagicMock(url='http://localhost/ansible2400.zip')

    mocked_resolve_func = MagicMock()
    mocked_resolver.resolve.return_value = mocked_resolve_func

    repo.get_dependencies(ireq)

    # Check that RequirementPreparer init is called with correct
    # type arguments
    assert mocked_init.call_count == 1
    (init_call_args, init_call_kwargs) = mocked_init.call_args
    assert isinstance(init_call_kwargs.get('build_dir'), str)
    assert isinstance(init_call_kwargs.get('src_dir'), str)
    assert isinstance(init_call_kwargs.get('download_dir'), str)
    assert isinstance(init_call_kwargs.get('wheel_download_dir'), str)
Ejemplo n.º 7
0
def ireq(line, extras=None):
    sorted_extras = ','.join(sorted((extras or '').split(',')))
    extras_str = '[{}]'.format(sorted_extras) if sorted_extras else ''
    parts = re.split('([<>=])', line)
    line_with_extras = parts[0] + extras_str + ''.join(parts[1:])
    return install_req_from_line(line_with_extras)
Ejemplo n.º 8
0
def test_incompatible_requirements():
    ireq_a = install_req_from_line('dummy==1.5')
    ireq_b = install_req_from_line('dummy==2.6')
    incompatible_reqs = IncompatibleRequirements(ireq_a, ireq_b)
    assert '{}'.format(incompatible_reqs) == (
        "Incompatible requirements found: dummy==1.5 and dummy==2.6")
Ejemplo n.º 9
0
def test_unsupported_constraint_simple():
    msg = "Foo bar distribution is not supported"
    ireq = install_req_from_line('foo-bar')
    unsupported_constraint = UnsupportedConstraint(msg, ireq)
    assert '{}'.format(unsupported_constraint) == (
        "Foo bar distribution is not supported (constraint was: foo-bar)")