From fba8ee7abecb12726293438e8af19d7c3fa54bb8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 12:22:53 -0500 Subject: Remove try/except/fail - Exceptions are failures by default. --- pkg_resources/tests/test_resources.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 6cc3de0b..82a987b7 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -593,10 +593,8 @@ class TestNamespaces: pkg2_init.close() import pkg1 assert "pkg1" in pkg_resources._namespace_packages - try: - import pkg1.pkg2 - except ImportError: - self.fail("Setuptools tried to import the parent namespace package") + # attempt to import pkg2 from site-pkgs2 + import pkg1.pkg2 # check the _namespace_packages dict assert "pkg1.pkg2" in pkg_resources._namespace_packages assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"] -- cgit v1.2.3 From db8efa2a8141205c405cd36f8c8a1aa0b1b7defa Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 12:25:38 -0500 Subject: Extract variable --- pkg_resources/tests/test_resources.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 82a987b7..fbb9db62 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -210,10 +210,8 @@ class TestEntryPoints: assert ep.attrs == ("TestEntryPoints",) assert ep.extras == ("x",) assert ep.load() is TestEntryPoints - assert ( - str(ep) == - "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]" - ) + expect = "foo = pkg_resources.tests.test_resources:TestEntryPoints [x]" + assert str(ep) == expect def setup_method(self, method): self.dist = Distribution.from_filename( -- cgit v1.2.3 From d8de6c98d879adbe5b8df731a5b61c06a48b9a2f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 12:43:13 -0500 Subject: Add another assertion on the exception. --- pkg_resources/tests/test_resources.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index fbb9db62..cf16bf03 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -172,9 +172,12 @@ class TestDistro: # Activation list now includes resolved dependency assert list(ws.resolve(parse_requirements("Foo[bar]"), ad)) ==[Foo,Baz] # Requests for conflicting versions produce VersionConflict - with pytest.raises(VersionConflict): + with pytest.raises(VersionConflict) as vc: ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad) + msg = 'Foo 0.9 is installed but Foo==1.2 is required by []' + assert str(vc).endswith(msg) + def testDistroDependsOptions(self): d = self.distRequires(""" Twisted>=1.5 -- cgit v1.2.3 From 880ccea0220509bfaf483a50beefc128299a5b03 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 13:00:50 -0500 Subject: Add test for WorkingSet.find() when a conflict occurs. --- pkg_resources/tests/test_resources.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index cf16bf03..79961e6c 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -205,6 +205,22 @@ class TestDistro: d.requires(["foo"]) +class TestWorkingSet: + def test_find_conflicting(self): + ws = WorkingSet([]) + Foo = Distribution.from_filename("/foo_dir/Foo-1.2.egg") + ws.add(Foo) + + # create a requirement that conflicts with Foo 1.2 + req = next(parse_requirements("Foo<1.2")) + + with pytest.raises(VersionConflict) as vc: + ws.find(req) + + msg = 'Foo 1.2 is installed but Foo<1.2 is required' + assert str(vc).endswith(msg) + + class TestEntryPoints: def assertfields(self, ep): -- cgit v1.2.3 From 23d5e4a81a61c5e6617fa69fd0b2bc440fa20c45 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 13:25:28 -0500 Subject: Test the report method --- pkg_resources/tests/test_resources.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 79961e6c..5cf3a657 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -175,8 +175,8 @@ class TestDistro: with pytest.raises(VersionConflict) as vc: ws.resolve(parse_requirements("Foo==1.2\nFoo!=1.2"), ad) - msg = 'Foo 0.9 is installed but Foo==1.2 is required by []' - assert str(vc).endswith(msg) + msg = 'Foo 0.9 is installed but Foo==1.2 is required' + assert vc.value.report() == msg def testDistroDependsOptions(self): d = self.distRequires(""" @@ -218,7 +218,7 @@ class TestWorkingSet: ws.find(req) msg = 'Foo 1.2 is installed but Foo<1.2 is required' - assert str(vc).endswith(msg) + assert vc.value.report() == msg class TestEntryPoints: -- cgit v1.2.3 From 72e3a1ce5986c54fed71da1f65aed4022008511f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 14:13:05 -0500 Subject: Normalize whitespace --- pkg_resources/tests/test_resources.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 5cf3a657..13ed4eb1 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -23,21 +23,23 @@ def safe_repr(obj, short=False): return result return result[:pkg_resources._MAX_LENGTH] + ' [truncated]...' + class Metadata(pkg_resources.EmptyProvider): """Mock object to return metadata as if from an on-disk distribution""" - def __init__(self,*pairs): + def __init__(self, *pairs): self.metadata = dict(pairs) - def has_metadata(self,name): + def has_metadata(self, name): return name in self.metadata - def get_metadata(self,name): + def get_metadata(self, name): return self.metadata[name] - def get_metadata_lines(self,name): + def get_metadata_lines(self, name): return pkg_resources.yield_lines(self.get_metadata(name)) + dist_from_fn = pkg_resources.Distribution.from_filename class TestDistro: -- cgit v1.2.3 From cdb9797a1107afd4d7baf021b2af84946d349a2a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 14:24:22 -0500 Subject: Add test capturing expectation when dependencies conflict during resolve. Fixes #281 --- pkg_resources/tests/test_resources.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 13ed4eb1..7ba65786 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -222,6 +222,31 @@ class TestWorkingSet: msg = 'Foo 1.2 is installed but Foo<1.2 is required' assert vc.value.report() == msg + def test_resolve_conflicts_with_prior(self): + """ + A ContextualVersionConflict should be raised when a requirement + conflicts with a prior requirement for a different package. + """ + # Create installation where Foo depends on Baz 1.0 and Bar depends on + # Baz 2.0. + ws = WorkingSet([]) + md = Metadata(('depends.txt', "Baz==1.0")) + Foo = Distribution.from_filename("/foo_dir/Foo-1.0.egg", metadata=md) + ws.add(Foo) + md = Metadata(('depends.txt', "Baz==2.0")) + Bar = Distribution.from_filename("/foo_dir/Bar-1.0.egg", metadata=md) + ws.add(Bar) + Baz = Distribution.from_filename("/foo_dir/Baz-1.0.egg") + ws.add(Baz) + Baz = Distribution.from_filename("/foo_dir/Baz-2.0.egg") + ws.add(Baz) + + with pytest.raises(VersionConflict) as vc: + ws.resolve(parse_requirements("Foo\nBar\n")) + + msg = "Baz 1.0 is installed but Baz==2.0 is required by {'Bar'}" + assert vc.value.report() == msg + class TestEntryPoints: -- cgit v1.2.3 From 0b7d713f812e7d84f143bd84f0734ae77169bb68 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 14:28:07 -0500 Subject: Fix test failure on Python 2 --- pkg_resources/tests/test_resources.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 7ba65786..f252ddff 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -245,6 +245,8 @@ class TestWorkingSet: ws.resolve(parse_requirements("Foo\nBar\n")) msg = "Baz 1.0 is installed but Baz==2.0 is required by {'Bar'}" + if pkg_resources.PY2: + msg = msg.replace("{'Bar'}", "set(['Bar'])") assert vc.value.report() == msg -- cgit v1.2.3 From 32ce474415accc4ad11fdbab57f7a65176d4197b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Jan 2015 09:48:30 -0500 Subject: Restore support for printable characters in the entry point name. Fixes #327. --- pkg_resources/tests/test_resources.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index f252ddff..4a82167b 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -2,6 +2,7 @@ import os import sys import tempfile import shutil +import string import pytest @@ -302,6 +303,16 @@ class TestEntryPoints: except ValueError: pass else: raise AssertionError("Should've been bad", ep) + def test_printable_name(self): + """ + Allow any printable character in the name. + """ + # Create a name with all printable characters; strip the whitespace. + name = string.printable.strip() + spec = "{name} = module:attr".format(**locals()) + ep = EntryPoint.parse(spec) + assert ep.name == name + def checkSubMap(self, m): assert len(m) == len(self.submap_expect) for key, ep in pkg_resources.iteritems(self.submap_expect): -- cgit v1.2.3 From 1524a98d7e0e5344134ef51e77cfe5a04e582a8f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Jan 2015 10:01:51 -0500 Subject: Equal signs are now allowed in entry point names. --- pkg_resources/tests/test_resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 4a82167b..00ba0cf5 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -297,7 +297,7 @@ class TestEntryPoints: def testRejects(self): for ep in [ - "foo", "x=1=2", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2", + "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2", ]: try: EntryPoint.parse(ep) except ValueError: pass -- cgit v1.2.3 From de11e9e9b57db01e029657acb1148a9fd70581b5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Jan 2015 10:02:44 -0500 Subject: Refactor for clarity --- pkg_resources/tests/test_resources.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 00ba0cf5..36cb6482 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -296,9 +296,8 @@ class TestEntryPoints: assert ep.name == 'html+mako' def testRejects(self): - for ep in [ - "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2", - ]: + specs = "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2" + for ep in specs: try: EntryPoint.parse(ep) except ValueError: pass else: raise AssertionError("Should've been bad", ep) -- cgit v1.2.3 From 9d04e13b60ccd4ec6058c31e219d6e7d124f9574 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Jan 2015 10:07:03 -0500 Subject: Use pytests parametrize to create separate tests for each spec --- pkg_resources/tests/test_resources.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 36cb6482..9c1eaeec 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -295,12 +295,12 @@ class TestEntryPoints: ep = EntryPoint.parse(spec) assert ep.name == 'html+mako' - def testRejects(self): - specs = "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2" - for ep in specs: - try: EntryPoint.parse(ep) - except ValueError: pass - else: raise AssertionError("Should've been bad", ep) + reject_specs = "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2" + @pytest.mark.parametrize("reject_spec", reject_specs) + def test_reject_spec(self, reject_spec): + try: EntryPoint.parse(reject_spec) + except ValueError: pass + else: raise AssertionError("Should've been bad", reject_spec) def test_printable_name(self): """ -- cgit v1.2.3 From 7d4bd8dabb45242671527282474c84179c967ede Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Jan 2015 10:08:15 -0500 Subject: Use pytest.raises for brevity and clarity of purpose. --- pkg_resources/tests/test_resources.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 9c1eaeec..a55478a2 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -298,9 +298,8 @@ class TestEntryPoints: reject_specs = "foo", "x=a:b:c", "q=x/na", "fez=pish:tush-z", "x=f[a]>2" @pytest.mark.parametrize("reject_spec", reject_specs) def test_reject_spec(self, reject_spec): - try: EntryPoint.parse(reject_spec) - except ValueError: pass - else: raise AssertionError("Should've been bad", reject_spec) + with pytest.raises(ValueError): + EntryPoint.parse(reject_spec) def test_printable_name(self): """ -- cgit v1.2.3 From a54a764326d516950861d2d317150e7e172bd99f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 20 Mar 2015 11:26:02 -0400 Subject: Add test capturing failure to parse package names with hyphens. Ref #307 --- pkg_resources/tests/test_resources.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index a55478a2..92f076a1 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -207,6 +207,16 @@ class TestDistro: with pytest.raises(pkg_resources.UnknownExtra): d.requires(["foo"]) + def test_pkg_name_with_hyphen(self): + "Package names with hyphens are supported" + name = 'setuptools-markdown-1.0.egg' + dist = Distribution.from_filename(name) + assert dist.project_name == "setuptools-markdown" + assert dist.key == "setuptools-markdown" + assert dist.version == "1.0" + assert dist.py_version is None + assert dist.platform is None + class TestWorkingSet: def test_find_conflicting(self): -- cgit v1.2.3 From 8ae39ab3a0bb12f17d2cabfdc27725b0992ba3c3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 20 Mar 2015 15:53:44 -0400 Subject: Backed out changeset 6e045b2724d0 and 56d7ea3d42b2. Ref #307. --- pkg_resources/tests/test_resources.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'pkg_resources/tests/test_resources.py') diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 92f076a1..a55478a2 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -207,16 +207,6 @@ class TestDistro: with pytest.raises(pkg_resources.UnknownExtra): d.requires(["foo"]) - def test_pkg_name_with_hyphen(self): - "Package names with hyphens are supported" - name = 'setuptools-markdown-1.0.egg' - dist = Distribution.from_filename(name) - assert dist.project_name == "setuptools-markdown" - assert dist.key == "setuptools-markdown" - assert dist.version == "1.0" - assert dist.py_version is None - assert dist.platform is None - class TestWorkingSet: def test_find_conflicting(self): -- cgit v1.2.3