Esempio n. 1
0
def test_failing_setup_script(from_editable):
    repository = get_repository()
    failing_package_dir = os.path.join(
        os.path.split(__file__)[0], 'test_data', 'failing_package')
    failing_package_url = path_to_url(failing_package_dir)
    ireq = from_editable(failing_package_url)

    with pytest.raises(DependencyResolutionFailed) as excinfo:
        repository.get_dependencies(ireq)

    # Check the contents of the error message
    error_message = '{}'.format(excinfo.value)
    assert error_message.startswith(
        'Dependency resolution of {url} failed:\n'.format(
            url=failing_package_url))

    egg_info_failed = 'Command "python setup.py egg_info" failed'
    command_errored = (
        'Command errored out with exit status 1:'
        ' python setup.py egg_info Check the logs for full command output.')
    assert (egg_info_failed in error_message
            or command_errored in error_message)

    import_error = "No module named 'non_existing_setup_helper'"
    import_error2 = import_error.replace("'", '')  # On Python 2
    assert (import_error in error_message) or (import_error2 in error_message)
Esempio n. 2
0
def test_local_dir_package_is_not_archived(tmpdir, small_fake_package_dir):
    """
    Prequ will not create an archive for a local dir requirement.
    """
    cache_dir = str(tmpdir.mkdir('cache_dir'))
    pkg_dir = os.path.join(cache_dir, 'pkgs')
    os.mkdir(pkg_dir)

    fake_package_url = path_to_url(small_fake_package_dir)

    with mock.patch('prequ.repositories.pypi.CACHE_DIR', new=cache_dir):
        runner = CliRunner()
        with runner.isolated_filesystem():
            with open('requirements.in', 'w') as req_in:
                req_in.write(fake_package_url)

            run_result = runner.invoke(cli, ['-n', '--no-header'])

            assert run_result.exit_code == 0
            assert run_result.output == (
                fake_package_url + '\n' +
                'six==1.10.0               # via small-fake-with-deps\n'
                'Dry-run, so nothing updated.\n')

    assert os.listdir(pkg_dir) == [], "Package directory should be empty"
Esempio n. 3
0
def test_format_requirement_non_relative_editable(from_editable,
                                                  small_fake_package_dir,
                                                  tmpdir):
    tmp_package_dir = os.path.join(str(tmpdir), 'small_fake_package')
    shutil.copytree(small_fake_package_dir, tmp_package_dir)
    ireq = from_editable(tmp_package_dir)
    assert format_requirement(ireq) == '-e ' + path_to_url(tmp_package_dir)
Esempio n. 4
0
def test_locally_available_editable_package_is_not_archived_in_cache_dir(
        tmpdir):
    """ Prequ will not create an archive for a locally available editable requirement """
    cache_dir = tmpdir.mkdir('cache_dir')
    os.mkdir(os.path.join(str(cache_dir), 'pkgs'))

    fake_package_dir = os.path.join(
        os.path.split(__file__)[0], 'test_data', 'small_fake_package')
    fake_package_dir = path_to_url(fake_package_dir)

    with mock.patch('prequ.repositories.pypi.CACHE_DIR', new=str(cache_dir)):
        runner = CliRunner()
        with runner.isolated_filesystem():
            with open('requirements.in', 'w') as req_in:
                req_in.write('-e ' +
                             fake_package_dir)  # require editable fake package

            out = runner.invoke(cli, ['-n'])

            assert out.exit_code == 0
            assert fake_package_dir in out.output
            assert 'six==1.10.0' in out.output

    # we should not find any archived file in {cache_dir}/pkgs
    assert not os.listdir(os.path.join(str(cache_dir), 'pkgs'))
Esempio n. 5
0
def test_sync_with_editable(from_editable, small_fake_package_dir):
    with mock.patch('prequ.sync.check_call') as check_call:
        to_install = {from_editable(small_fake_package_dir)}

        sync(to_install, set())
        check_call.assert_called_once_with([
            'pip', 'install', '-q', '-e',
            path_to_url(small_fake_package_dir)
        ])
Esempio n. 6
0
def test_sync_with_editable_uses_abspath(from_editable,
                                         small_fake_package_dir):
    ireq = from_editable(small_fake_package_dir)
    rel_path = os.path.relpath(url_to_path(ireq.link.url))
    ireq.link.url = 'file:{}'.format(rel_path.replace(os.path.sep, '/'))
    with mock.patch('prequ.sync.check_call') as check_call:
        sync({ireq}, set())
        check_call.assert_called_once_with([
            'pip', 'install', '-q', '-e',
            path_to_url(os.path.abspath(small_fake_package_dir))
        ])
Esempio n. 7
0
def test_editable_package(small_fake_package_dir):
    """Prequ can compile an editable """
    small_fake_package_url = path_to_url(small_fake_package_dir)
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('requirements.in', 'w') as req_in:
            req_in.write('-e ' + small_fake_package_url)

        out = runner.invoke(cli, ['-n'])

        check_successful_exit(out)
        assert small_fake_package_url in out.output
        assert '-e ' + small_fake_package_url in out.output
        assert 'six==1.10.0' in out.output
Esempio n. 8
0
def test_sync_with_editable_uses_abspath(from_editable, small_fake_package_dir,
                                         mocked_tmp_req_file):
    ireq = from_editable(small_fake_package_dir)
    rel_path = os.path.relpath(url_to_path(ireq.link.url))
    url = 'file:{}'.format(rel_path.replace(os.path.sep, '/'))
    if hasattr(ireq.link, '_url'):
        ireq.link._url = url
    else:
        ireq.link.url = url
    with mock.patch('prequ.sync.check_call'):
        sync({ireq}, set())

        fake_pkg_url = path_to_url(os.path.abspath(small_fake_package_dir))
        mocked_tmp_req_file.write.assert_called_once_with(
            '-e {}'.format(fake_pkg_url))
Esempio n. 9
0
def test_diff_with_editable(fake_dist, from_editable, from_line,
                            small_fake_package_dir):
    installed = [
        fake_dist('small-fake-with-deps==0.0.1'),
        fake_dist('six==1.10.0'),
    ]
    reqs = [
        from_editable(small_fake_package_dir),
        from_line('six==1.10.0'),
    ]
    to_install, to_uninstall = diff(reqs, installed)

    assert to_uninstall == set(), "No packages should be uninstalled"

    # The editable should be upgraded, since the installed version
    # (0.0.1) was different than the version specified in setup.py of
    # the editable package (0.1)
    assert len(to_install) == 1
    package = list(to_install)[0]
    assert package.editable
    assert str(package.link) == path_to_url(small_fake_package_dir)
Esempio n. 10
0
def test_generate_hashes_with_editable():
    small_fake_package_dir = os.path.join(
        os.path.split(__file__)[0], 'test_data', 'small_fake_package')
    small_fake_package_url = path_to_url(small_fake_package_dir)
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open('requirements.in', 'w') as fp:
            fp.write('-e {}\n'.format(small_fake_package_url))
            fp.write('pytz==2017.2\n')
        out = runner.invoke(cli, ['--generate-hashes'])
    expected = (
        '# This file is autogenerated by Prequ.  To update, run:\n'
        '#\n'
        '#   prequ update\n'
        '#\n'
        '-e {}\n'
        'pytz==2017.2 \\\n'
        '    --hash=sha256:d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67 \\\n'
        '    --hash=sha256:f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589\n'
    ).format(small_fake_package_url)
    assert out.exit_code == 0
    assert expected in out.output