aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources/tests
diff options
context:
space:
mode:
authorLeonardo Rochael Almeida <leorochael@gmail.com>2017-07-31 16:29:32 -0300
committerLeonardo Rochael Almeida <leorochael@gmail.com>2017-07-31 16:29:32 -0300
commite265e4560965878531fea7856fb165a182908b8d (patch)
treea7a988aa3b3f04652918c408cf55dfbcfe0d4aa9 /pkg_resources/tests
parent80848f95f295464639bfd349e62d40d2e279fa76 (diff)
downloadexternal_python_setuptools-e265e4560965878531fea7856fb165a182908b8d.tar.gz
external_python_setuptools-e265e4560965878531fea7856fb165a182908b8d.tar.bz2
external_python_setuptools-e265e4560965878531fea7856fb165a182908b8d.zip
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
Diffstat (limited to 'pkg_resources/tests')
-rw-r--r--pkg_resources/tests/test_find_distributions.py65
1 files changed, 65 insertions, 0 deletions
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)