Commit e065e901 authored by Jason R. Coombs's avatar Jason R. Coombs

Feed the hobgoblins (delint).

parent c9ecd46f
......@@ -1307,7 +1307,7 @@ class ResourceManager:
target_path = os.path.join(extract_path, archive_name + '-tmp', *names)
try:
_bypass_ensure_directory(target_path)
except:
except Exception:
self.extraction_error()
self._warn_unsafe_extraction_path(extract_path)
......
......@@ -13,6 +13,7 @@ setuptools.setup(
)
""".lstrip()
class TestFindDistributions:
@pytest.fixture
......
......@@ -154,8 +154,10 @@ class TestIndependence:
lines = (
'import pkg_resources',
'import sys',
'assert "setuptools" not in sys.modules, '
'"setuptools was imported"',
(
'assert "setuptools" not in sys.modules, '
'"setuptools was imported"'
),
)
cmd = [sys.executable, '-c', '; '.join(lines)]
subprocess.check_call(cmd)
......
......@@ -11,7 +11,8 @@ import pytest
from pkg_resources.extern import packaging
import pkg_resources
from pkg_resources import (parse_requirements, VersionConflict, parse_version,
from pkg_resources import (
parse_requirements, VersionConflict, parse_version,
Distribution, EntryPoint, Requirement, safe_version, safe_name,
WorkingSet)
......@@ -51,7 +52,8 @@ class TestDistro:
assert list(ad) == ['foopkg']
# Distributions sort by version
assert [dist.version for dist in ad['FooPkg']] == ['1.4', '1.3-1', '1.2']
expected = ['1.4', '1.3-1', '1.2']
assert [dist.version for dist in ad['FooPkg']] == expected
# Removing a distribution leaves sequence alone
ad.remove(ad['FooPkg'][1])
......@@ -97,7 +99,10 @@ class TestDistro:
def testDistroBasics(self):
d = Distribution(
"/some/path",
project_name="FooPkg", version="1.3-1", py_version="2.4", platform="win32"
project_name="FooPkg",
version="1.3-1",
py_version="2.4",
platform="win32",
)
self.checkFooPkg(d)
......@@ -113,10 +118,11 @@ class TestDistro:
def testDistroMetadata(self):
d = Distribution(
"/some/path", project_name="FooPkg", py_version="2.4", platform="win32",
"/some/path", project_name="FooPkg",
py_version="2.4", platform="win32",
metadata=Metadata(
('PKG-INFO', "Metadata-Version: 1.0\nVersion: 1.3-1\n")
)
),
)
self.checkFooPkg(d)
......@@ -164,7 +170,10 @@ class TestDistro:
ad.add(Baz)
# Activation list now includes resolved dependency
assert list(ws.resolve(parse_requirements("Foo[bar]"), ad)) == [Foo, Baz]
assert (
list(ws.resolve(parse_requirements("Foo[bar]"), ad))
== [Foo, Baz]
)
# Requests for conflicting versions produce VersionConflict
with pytest.raises(VersionConflict) as vc:
ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad)
......@@ -415,7 +424,8 @@ class TestEntryPoints:
submap_expect = dict(
feature1=EntryPoint('feature1', 'somemodule', ['somefunction']),
feature2=EntryPoint('feature2', 'another.module', ['SomeClass'], ['extra1', 'extra2']),
feature2=EntryPoint(
'feature2', 'another.module', ['SomeClass'], ['extra1', 'extra2']),
feature3=EntryPoint('feature3', 'this.module', extras=['something'])
)
submap_str = """
......@@ -518,11 +528,17 @@ class TestRequirements:
Requirement.parse('setuptools').project_name == 'setuptools')
# setuptools 0.7 and higher means setuptools.
assert (
Requirement.parse('setuptools == 0.7').project_name == 'setuptools')
Requirement.parse('setuptools == 0.7').project_name
== 'setuptools'
)
assert (
Requirement.parse('setuptools == 0.7a1').project_name == 'setuptools')
Requirement.parse('setuptools == 0.7a1').project_name
== 'setuptools'
)
assert (
Requirement.parse('setuptools >= 0.7').project_name == 'setuptools')
Requirement.parse('setuptools >= 0.7').project_name
== 'setuptools'
)
class TestParsing:
......@@ -552,7 +568,7 @@ class TestParsing:
"""
assert (
list(pkg_resources.split_sections(sample))
==
==
[
(None, ["x"]),
("Y", ["z", "a"]),
......@@ -838,7 +854,8 @@ class TestNamespaces:
subpkg = nspkg / 'subpkg'
subpkg.ensure_dir()
(nspkg / '__init__.py').write_text(self.ns_str, encoding='utf-8')
(subpkg / '__init__.py').write_text(vers_str % number, encoding='utf-8')
(subpkg / '__init__.py').write_text(
vers_str % number, encoding='utf-8')
import nspkg.subpkg
import nspkg
......
import inspect
import re
import textwrap
import functools
import pytest
......@@ -15,6 +16,7 @@ def strip_comments(s):
if l.strip() and not l.strip().startswith('#')
)
def parse_distributions(s):
'''
Parse a series of distribution specs of the form:
......@@ -31,7 +33,8 @@ def parse_distributions(s):
yield 2 distributions:
- project_name=foo, version=0.2
- project_name=bar, version=1.0, requires=['foo>=3.0', 'baz; extra=="feature"']
- project_name=bar, version=1.0,
requires=['foo>=3.0', 'baz; extra=="feature"']
'''
s = s.strip()
for spec in re.split('\n(?=[^\s])', s):
......@@ -42,7 +45,7 @@ def parse_distributions(s):
name, version = fields.pop(0).split('-')
if fields:
requires = textwrap.dedent(fields.pop(0))
metadata=Metadata(('requires.txt', requires))
metadata = Metadata(('requires.txt', requires))
else:
metadata = None
dist = pkg_resources.Distribution(project_name=name,
......@@ -467,7 +470,8 @@ def test_working_set_resolve(installed_dists, installable_dists, requirements,
replace_conflicting, resolved_dists_or_exception):
ws = pkg_resources.WorkingSet([])
list(map(ws.add, installed_dists))
resolve_call = lambda: ws.resolve(
resolve_call = functools.partial(
ws.resolve,
requirements, installer=FakeInstaller(installable_dists),
replace_conflicting=replace_conflicting,
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment