diff options
Diffstat (limited to 'setuptools/tests/test_packageindex.py')
-rw-r--r-- | setuptools/tests/test_packageindex.py | 85 |
1 files changed, 28 insertions, 57 deletions
diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py index 60d968fd..8e9435ef 100644 --- a/setuptools/tests/test_packageindex.py +++ b/setuptools/tests/test_packageindex.py @@ -1,17 +1,15 @@ -from __future__ import absolute_import - import sys import os import distutils.errors +import platform +import urllib.request +import urllib.error +import http.client -from setuptools.extern import six -from setuptools.extern.six.moves import urllib, http_client import mock import pytest -import pkg_resources import setuptools.package_index -from setuptools.tests.server import IndexServer from .textwrap import DALS @@ -61,7 +59,7 @@ class TestPackageIndex: ) def _urlopen(*args): - raise http_client.BadStatusLine('line') + raise http.client.BadStatusLine('line') index.opener = _urlopen url = 'http://example.com' @@ -85,7 +83,7 @@ class TestPackageIndex: try: index.open_url(url) except distutils.errors.DistutilsError as error: - msg = six.text_type(error) + msg = str(error) assert ( 'nonnumeric port' in msg or 'getaddrinfo failed' in msg @@ -114,43 +112,6 @@ class TestPackageIndex: url = 'file:///tmp/test_package_index' assert index.url_ok(url, True) - def test_links_priority(self): - """ - Download links from the pypi simple index should be used before - external download links. - https://bitbucket.org/tarek/distribute/issue/163 - - Usecase : - - someone uploads a package on pypi, a md5 is generated - - someone manually copies this link (with the md5 in the url) onto an - external page accessible from the package page. - - someone reuploads the package (with a different md5) - - while easy_installing, an MD5 error occurs because the external link - is used - -> Setuptools should use the link from pypi, not the external one. - """ - if sys.platform.startswith('java'): - # Skip this test on jython because binding to :0 fails - return - - # start an index server - server = IndexServer() - server.start() - index_url = server.base_url() + 'test_links_priority/simple/' - - # scan a test index - pi = setuptools.package_index.PackageIndex(index_url) - requirement = pkg_resources.Requirement.parse('foobar') - pi.find_packages(requirement) - server.stop() - - # the distribution has been found - assert 'foobar' in pi - # we have only one link, because links are compared without md5 - assert len(pi['foobar']) == 1 - # the link should be from the index - assert 'correct_md5' in pi['foobar'][0].location - def test_parse_bdist_wininst(self): parse = setuptools.package_index.parse_bdist_wininst @@ -221,11 +182,11 @@ class TestPackageIndex: ('+ubuntu_0', '+ubuntu.0'), ] versions = [ - [''.join([e, r, p, l]) for l in ll] + [''.join([e, r, p, loc]) for loc in locs] for e in epoch for r in releases for p in sum([pre, post, dev], ['']) - for ll in local] + for locs in local] for v, vc in versions: dists = list(setuptools.package_index.distros_for_url( 'http://example.com/example.zip#egg=example-' + v)) @@ -322,17 +283,27 @@ class TestContentCheckers: assert rep == 'My message about md5' +@pytest.fixture +def temp_home(tmpdir, monkeypatch): + key = ( + 'USERPROFILE' + if platform.system() == 'Windows' and sys.version_info > (3, 8) else + 'HOME' + ) + + monkeypatch.setitem(os.environ, key, str(tmpdir)) + return tmpdir + + class TestPyPIConfig: - def test_percent_in_password(self, tmpdir, monkeypatch): - monkeypatch.setitem(os.environ, 'HOME', str(tmpdir)) - pypirc = tmpdir / '.pypirc' - with pypirc.open('w') as strm: - strm.write(DALS(""" - [pypi] - repository=https://pypi.org - username=jaraco - password=pity% - """)) + def test_percent_in_password(self, temp_home): + pypirc = temp_home / '.pypirc' + pypirc.write(DALS(""" + [pypi] + repository=https://pypi.org + username=jaraco + password=pity% + """)) cfg = setuptools.package_index.PyPIConfig() cred = cfg.creds_by_repository['https://pypi.org'] assert cred.username == 'jaraco' |