From e265e4560965878531fea7856fb165a182908b8d Mon Sep 17 00:00:00 2001 From: Leonardo Rochael Almeida Date: Mon, 31 Jul 2017 16:29:32 -0300 Subject: Better detect unpacked eggs Do not assume a directory named in `.egg` is an egg, unless it has an actual egg metadata directory. Closes #462 --- pkg_resources/tests/test_find_distributions.py | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 pkg_resources/tests/test_find_distributions.py (limited to 'pkg_resources/tests/test_find_distributions.py') diff --git a/pkg_resources/tests/test_find_distributions.py b/pkg_resources/tests/test_find_distributions.py new file mode 100644 index 00000000..97999b33 --- /dev/null +++ b/pkg_resources/tests/test_find_distributions.py @@ -0,0 +1,65 @@ +import subprocess +import sys + +import pytest +import pkg_resources + +SETUP_TEMPLATE = """ +import setuptools +setuptools.setup( + name="my-test-package", + version="1.0", + zip_safe=True, +) +""".lstrip() + +class TestFindDistributions: + + @pytest.fixture + def target_dir(self, tmpdir): + target_dir = tmpdir.mkdir('target') + # place a .egg named directory in the target that is not an egg: + target_dir.mkdir('not.an.egg') + return str(target_dir) + + @pytest.fixture + def project_dir(self, tmpdir): + project_dir = tmpdir.mkdir('my-test-package') + (project_dir / "setup.py").write(SETUP_TEMPLATE) + return str(project_dir) + + def test_non_egg_dir_named_egg(self, target_dir): + dists = pkg_resources.find_distributions(target_dir) + assert not list(dists) + + def test_standalone_egg_directory(self, project_dir, target_dir): + # install this distro as an unpacked egg: + args = [ + sys.executable, + '-c', 'from setuptools.command.easy_install import main; main()', + '-mNx', + '-d', target_dir, + '--always-unzip', + project_dir, + ] + subprocess.check_call(args) + dists = pkg_resources.find_distributions(target_dir) + assert [dist.project_name for dist in dists] == ['my-test-package'] + dists = pkg_resources.find_distributions(target_dir, only=True) + assert not list(dists) + + def test_zipped_egg(self, project_dir, target_dir): + # install this distro as an unpacked egg: + args = [ + sys.executable, + '-c', 'from setuptools.command.easy_install import main; main()', + '-mNx', + '-d', target_dir, + '--zip-ok', + project_dir, + ] + subprocess.check_call(args) + dists = pkg_resources.find_distributions(target_dir) + assert [dist.project_name for dist in dists] == ['my-test-package'] + dists = pkg_resources.find_distributions(target_dir, only=True) + assert not list(dists) -- cgit v1.2.1 From e065e9012612f3e0b8713fd61d298126f7fcfa21 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Mar 2018 12:24:12 -0500 Subject: Feed the hobgoblins (delint). --- pkg_resources/tests/test_find_distributions.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pkg_resources/tests/test_find_distributions.py') diff --git a/pkg_resources/tests/test_find_distributions.py b/pkg_resources/tests/test_find_distributions.py index 97999b33..d735c590 100644 --- a/pkg_resources/tests/test_find_distributions.py +++ b/pkg_resources/tests/test_find_distributions.py @@ -13,6 +13,7 @@ setuptools.setup( ) """.lstrip() + class TestFindDistributions: @pytest.fixture -- cgit v1.2.1 From 14c82188dae748fb7a7dd126fb2a5553e4865c95 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Tue, 8 Oct 2019 12:18:31 +0200 Subject: test: drop pkg_resources tests dependency on easy_install --- pkg_resources/tests/test_find_distributions.py | 58 ++++++-------------------- 1 file changed, 13 insertions(+), 45 deletions(-) (limited to 'pkg_resources/tests/test_find_distributions.py') diff --git a/pkg_resources/tests/test_find_distributions.py b/pkg_resources/tests/test_find_distributions.py index d735c590..f9594422 100644 --- a/pkg_resources/tests/test_find_distributions.py +++ b/pkg_resources/tests/test_find_distributions.py @@ -1,17 +1,9 @@ -import subprocess -import sys - +import py import pytest import pkg_resources -SETUP_TEMPLATE = """ -import setuptools -setuptools.setup( - name="my-test-package", - version="1.0", - zip_safe=True, -) -""".lstrip() + +TESTS_DATA_DIR = py.path.local(__file__).dirpath('data') class TestFindDistributions: @@ -21,46 +13,22 @@ class TestFindDistributions: target_dir = tmpdir.mkdir('target') # place a .egg named directory in the target that is not an egg: target_dir.mkdir('not.an.egg') - return str(target_dir) - - @pytest.fixture - def project_dir(self, tmpdir): - project_dir = tmpdir.mkdir('my-test-package') - (project_dir / "setup.py").write(SETUP_TEMPLATE) - return str(project_dir) + return target_dir def test_non_egg_dir_named_egg(self, target_dir): - dists = pkg_resources.find_distributions(target_dir) + dists = pkg_resources.find_distributions(str(target_dir)) assert not list(dists) - def test_standalone_egg_directory(self, project_dir, target_dir): - # install this distro as an unpacked egg: - args = [ - sys.executable, - '-c', 'from setuptools.command.easy_install import main; main()', - '-mNx', - '-d', target_dir, - '--always-unzip', - project_dir, - ] - subprocess.check_call(args) - dists = pkg_resources.find_distributions(target_dir) + def test_standalone_egg_directory(self, target_dir): + (TESTS_DATA_DIR / 'my-test-package_unpacked-egg').copy(target_dir) + dists = pkg_resources.find_distributions(str(target_dir)) assert [dist.project_name for dist in dists] == ['my-test-package'] - dists = pkg_resources.find_distributions(target_dir, only=True) + dists = pkg_resources.find_distributions(str(target_dir), only=True) assert not list(dists) - def test_zipped_egg(self, project_dir, target_dir): - # install this distro as an unpacked egg: - args = [ - sys.executable, - '-c', 'from setuptools.command.easy_install import main; main()', - '-mNx', - '-d', target_dir, - '--zip-ok', - project_dir, - ] - subprocess.check_call(args) - dists = pkg_resources.find_distributions(target_dir) + def test_zipped_egg(self, target_dir): + (TESTS_DATA_DIR / 'my-test-package_zipped-egg').copy(target_dir) + dists = pkg_resources.find_distributions(str(target_dir)) assert [dist.project_name for dist in dists] == ['my-test-package'] - dists = pkg_resources.find_distributions(target_dir, only=True) + dists = pkg_resources.find_distributions(str(target_dir), only=True) assert not list(dists) -- cgit v1.2.1 From 44d45ae20a663f1cb75812657cee1244e3dddb58 Mon Sep 17 00:00:00 2001 From: Tim Hatch Date: Mon, 14 Dec 2020 09:37:47 -0800 Subject: Failing test for #2489 --- pkg_resources/tests/test_find_distributions.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pkg_resources/tests/test_find_distributions.py') diff --git a/pkg_resources/tests/test_find_distributions.py b/pkg_resources/tests/test_find_distributions.py index f9594422..b01b4827 100644 --- a/pkg_resources/tests/test_find_distributions.py +++ b/pkg_resources/tests/test_find_distributions.py @@ -32,3 +32,12 @@ class TestFindDistributions: assert [dist.project_name for dist in dists] == ['my-test-package'] dists = pkg_resources.find_distributions(str(target_dir), only=True) assert not list(dists) + + def test_zipped_sdist_one_level_removed(self, target_dir): + (TESTS_DATA_DIR / 'my-test-package-zip').copy(target_dir) + dists = pkg_resources.find_distributions( + str(target_dir / "my-test-package.zip")) + assert [dist.project_name for dist in dists] == ['my-test-package'] + dists = pkg_resources.find_distributions( + str(target_dir / "my-test-package.zip"), only=True) + assert not list(dists) -- cgit v1.2.1