Skip to content

Commit

Permalink
⚫ Fade to black.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Nov 4, 2022
1 parent 6254567 commit 1f97905
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions setuptools/tests/test_packageindex.py
Expand Up @@ -21,7 +21,9 @@ def test_regex(self):
<a href="http://some_url">Name</a>
(<a title="MD5 hash"
href="{hash_url}">md5</a>)
""".lstrip().format(**locals())
""".lstrip().format(
**locals()
)
assert setuptools.package_index.PYPI_MD5.match(doc)

def test_bad_url_bad_port(self):
Expand All @@ -38,9 +40,7 @@ def test_bad_url_typo(self):
# issue 16
# easy_install inquant.contentmirror.plone breaks because of a typo
# in its home URL
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
index = setuptools.package_index.PackageIndex(hosts=('www.example.com',))

url = (
'url:%20https://svn.plone.org/svn'
Expand All @@ -54,9 +54,7 @@ def test_bad_url_typo(self):
assert isinstance(v, urllib.error.HTTPError)

def test_bad_url_bad_status_line(self):
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
index = setuptools.package_index.PackageIndex(hosts=('www.example.com',))

def _urlopen(*args):
raise http.client.BadStatusLine('line')
Expand All @@ -74,9 +72,7 @@ def test_bad_url_double_scheme(self):
"""
A bad URL with a double scheme should raise a DistutilsError.
"""
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
index = setuptools.package_index.PackageIndex(hosts=('www.example.com',))

# issue 20
url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk'
Expand All @@ -93,22 +89,17 @@ def test_bad_url_double_scheme(self):
raise RuntimeError("Did not raise")

def test_bad_url_screwy_href(self):
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
index = setuptools.package_index.PackageIndex(hosts=('www.example.com',))

# issue #160
if sys.version_info[0] == 2 and sys.version_info[1] == 7:
# this should not fail
url = 'http://example.com'
page = ('<a href="http://www.famfamfam.com]('
'http://www.famfamfam.com/">')
page = '<a href="http://www.famfamfam.com](' 'http://www.famfamfam.com/">'
index.process_index(url, page)

def test_url_ok(self):
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
index = setuptools.package_index.PackageIndex(hosts=('www.example.com',))
url = 'file:///tmp/test_package_index'
assert index.url_ok(url, True)

Expand Down Expand Up @@ -169,9 +160,7 @@ def test_egg_fragment(self):
'b0',
'rc0',
]
post = [
'.post0'
]
post = ['.post0']
dev = [
'.dev0',
]
Expand All @@ -186,10 +175,14 @@ def test_egg_fragment(self):
for e in epoch
for r in releases
for p in sum([pre, post, dev], [''])
for locs 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))
dists = list(
setuptools.package_index.distros_for_url(
'http://example.com/example.zip#egg=example-' + v
)
)
assert dists[0].version == ''
assert dists[1].version == vc

Expand All @@ -204,8 +197,7 @@ def test_download_git_with_rev(self, tmpdir):

expected_dir = str(tmpdir / 'project@master')
expected = (
'git clone --quiet '
'https://github.example/group/project {expected_dir}'
'git clone --quiet ' 'https://github.example/group/project {expected_dir}'
).format(**locals())
first_call_args = os_system_mock.call_args_list[0][0]
assert first_call_args == (expected,)
Expand All @@ -226,8 +218,7 @@ def test_download_git_no_rev(self, tmpdir):

expected_dir = str(tmpdir / 'project')
expected = (
'git clone --quiet '
'https://github.example/group/project {expected_dir}'
'git clone --quiet ' 'https://github.example/group/project {expected_dir}'
).format(**locals())
os_system_mock.assert_called_once_with(expected)

Expand All @@ -243,42 +234,44 @@ def test_download_svn(self, tmpdir):

expected_dir = str(tmpdir / 'project')
expected = (
'svn checkout -q '
'svn+https://svn.example/project {expected_dir}'
'svn checkout -q ' 'svn+https://svn.example/project {expected_dir}'
).format(**locals())
os_system_mock.assert_called_once_with(expected)


class TestContentCheckers:
def test_md5(self):
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478')
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478'
)
checker.feed('You should probably not be using MD5'.encode('ascii'))
assert checker.hash.hexdigest() == 'f12895fdffbd45007040d2e44df98478'
assert checker.is_valid()

def test_other_fragment(self):
"Content checks should succeed silently if no hash is present"
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#something%20completely%20different')
'http://foo/bar#something%20completely%20different'
)
checker.feed('anything'.encode('ascii'))
assert checker.is_valid()

def test_blank_md5(self):
"Content checks should succeed if a hash is empty"
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=')
checker = setuptools.package_index.HashChecker.from_url('http://foo/bar#md5=')
checker.feed('anything'.encode('ascii'))
assert checker.is_valid()

def test_get_hash_name_md5(self):
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478')
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478'
)
assert checker.hash_name == 'md5'

def test_report(self):
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478')
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478'
)
rep = checker.report(lambda x: x, 'My message about %s')
assert rep == 'My message about md5'

Expand All @@ -287,8 +280,8 @@ def test_report(self):
def temp_home(tmpdir, monkeypatch):
key = (
'USERPROFILE'
if platform.system() == 'Windows' and sys.version_info > (3, 8) else
'HOME'
if platform.system() == 'Windows' and sys.version_info > (3, 8)
else 'HOME'
)

monkeypatch.setitem(os.environ, key, str(tmpdir))
Expand All @@ -298,12 +291,16 @@ def temp_home(tmpdir, monkeypatch):
class TestPyPIConfig:
def test_percent_in_password(self, temp_home):
pypirc = temp_home / '.pypirc'
pypirc.write(DALS("""
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'
Expand Down

0 comments on commit 1f97905

Please sign in to comment.