aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources/tests/test_resources.py
diff options
context:
space:
mode:
authorSteve Kowalik <steven@wedontsleep.org>2016-04-04 16:27:32 +1000
committerSteve Kowalik <steven@wedontsleep.org>2016-04-05 16:50:48 +1000
commit1cdd940877e158f2b748f67f09d1f1321a113998 (patch)
tree351c75d2535d47ab2347641de42a6a4b38b99d6b /pkg_resources/tests/test_resources.py
parent9803058dc72867605bdac20d41249c00e8eae415 (diff)
downloadexternal_python_setuptools-1cdd940877e158f2b748f67f09d1f1321a113998.tar.gz
external_python_setuptools-1cdd940877e158f2b748f67f09d1f1321a113998.tar.bz2
external_python_setuptools-1cdd940877e158f2b748f67f09d1f1321a113998.zip
Restore evaluating environment markers in WorkingSet
Correctly deal with parsed requirements that include extras as a marker inside WorkingSet that are populated from METADATA inside wheels, like we get from pip>=7. This partially reverts commit 04d10ff025e1cbef7ec93a2008c930e856045c8a. Closes: #523
Diffstat (limited to 'pkg_resources/tests/test_resources.py')
-rw-r--r--pkg_resources/tests/test_resources.py79
1 files changed, 74 insertions, 5 deletions
diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py
index 98b8dcd7..7f86c797 100644
--- a/pkg_resources/tests/test_resources.py
+++ b/pkg_resources/tests/test_resources.py
@@ -171,16 +171,85 @@ class TestDistro:
msg = 'Foo 0.9 is installed but Foo==1.2 is required'
assert vc.value.report() == msg
- @pytest.mark.xfail(reason="Functionality disabled; see #523")
- def test_environment_markers(self):
- """
- Environment markers are evaluated at resolution time.
- """
+ def test_environment_marker_evaluation_negative(self):
+ """Environment markers are evaluated at resolution time."""
ad = pkg_resources.Environment([])
ws = WorkingSet([])
res = ws.resolve(parse_requirements("Foo;python_version<'2'"), ad)
assert list(res) == []
+ def test_environment_marker_evaluation_positive(self):
+ ad = pkg_resources.Environment([])
+ ws = WorkingSet([])
+ Foo = Distribution.from_filename("/foo_dir/Foo-1.2.dist-info")
+ ad.add(Foo)
+ res = ws.resolve(parse_requirements("Foo;python_version>='2'"), ad)
+ assert list(res) == [Foo]
+
+ def test_marker_evaluation_with_extras(self):
+ """Extras are also evaluated as markers at resolution time."""
+ ad = pkg_resources.Environment([])
+ ws = WorkingSet([])
+ # Metadata needs to be native strings due to cStringIO behaviour in
+ # 2.6, so use str().
+ Foo = Distribution.from_filename(
+ "/foo_dir/Foo-1.2.dist-info",
+ metadata=Metadata(("METADATA", str("Provides-Extra: baz\n"
+ "Requires-Dist: quux; extra=='baz'")))
+ )
+ ad.add(Foo)
+ assert list(ws.resolve(parse_requirements("Foo"), ad)) == [Foo]
+ quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
+ ad.add(quux)
+ res = list(ws.resolve(parse_requirements("Foo[baz]"), ad))
+ assert res == [Foo,quux]
+
+ def test_marker_evaluation_with_multiple_extras(self):
+ ad = pkg_resources.Environment([])
+ ws = WorkingSet([])
+ # Metadata needs to be native strings due to cStringIO behaviour in
+ # 2.6, so use str().
+ Foo = Distribution.from_filename(
+ "/foo_dir/Foo-1.2.dist-info",
+ metadata=Metadata(("METADATA", str("Provides-Extra: baz\n"
+ "Requires-Dist: quux; extra=='baz'\n"
+ "Provides-Extra: bar\n"
+ "Requires-Dist: fred; extra=='bar'\n")))
+ )
+ ad.add(Foo)
+ quux = Distribution.from_filename("/foo_dir/quux-1.0.dist-info")
+ ad.add(quux)
+ fred = Distribution.from_filename("/foo_dir/fred-0.1.dist-info")
+ ad.add(fred)
+ res = list(ws.resolve(parse_requirements("Foo[baz,bar]"), ad))
+ assert sorted(res) == [fred,quux,Foo]
+
+ def test_marker_evaluation_with_extras_loop(self):
+ ad = pkg_resources.Environment([])
+ ws = WorkingSet([])
+ # Metadata needs to be native strings due to cStringIO behaviour in
+ # 2.6, so use str().
+ a = Distribution.from_filename(
+ "/foo_dir/a-0.2.dist-info",
+ metadata=Metadata(("METADATA", str("Requires-Dist: c[a]")))
+ )
+ b = Distribution.from_filename(
+ "/foo_dir/b-0.3.dist-info",
+ metadata=Metadata(("METADATA", str("Requires-Dist: c[b]")))
+ )
+ c = Distribution.from_filename(
+ "/foo_dir/c-1.0.dist-info",
+ metadata=Metadata(("METADATA", str("Provides-Extra: a\n"
+ "Requires-Dist: b;extra=='a'\n"
+ "Provides-Extra: b\n"
+ "Requires-Dist: foo;extra=='b'")))
+ )
+ foo = Distribution.from_filename("/foo_dir/foo-0.1.dist-info")
+ for dist in (a, b, c, foo):
+ ad.add(dist)
+ res = list(ws.resolve(parse_requirements("a"), ad))
+ assert res == [a, c, b, foo]
+
def testDistroDependsOptions(self):
d = self.distRequires("""
Twisted>=1.5