• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import subprocess
2import sys
3
4import pytest
5import pkg_resources
6
7SETUP_TEMPLATE = """
8import setuptools
9setuptools.setup(
10    name="my-test-package",
11    version="1.0",
12    zip_safe=True,
13)
14""".lstrip()
15
16
17class TestFindDistributions:
18
19    @pytest.fixture
20    def target_dir(self, tmpdir):
21        target_dir = tmpdir.mkdir('target')
22        # place a .egg named directory in the target that is not an egg:
23        target_dir.mkdir('not.an.egg')
24        return str(target_dir)
25
26    @pytest.fixture
27    def project_dir(self, tmpdir):
28        project_dir = tmpdir.mkdir('my-test-package')
29        (project_dir / "setup.py").write(SETUP_TEMPLATE)
30        return str(project_dir)
31
32    def test_non_egg_dir_named_egg(self, target_dir):
33        dists = pkg_resources.find_distributions(target_dir)
34        assert not list(dists)
35
36    def test_standalone_egg_directory(self, project_dir, target_dir):
37        # install this distro as an unpacked egg:
38        args = [
39            sys.executable,
40            '-c', 'from setuptools.command.easy_install import main; main()',
41            '-mNx',
42            '-d', target_dir,
43            '--always-unzip',
44            project_dir,
45        ]
46        subprocess.check_call(args)
47        dists = pkg_resources.find_distributions(target_dir)
48        assert [dist.project_name for dist in dists] == ['my-test-package']
49        dists = pkg_resources.find_distributions(target_dir, only=True)
50        assert not list(dists)
51
52    def test_zipped_egg(self, project_dir, target_dir):
53        # install this distro as an unpacked egg:
54        args = [
55            sys.executable,
56            '-c', 'from setuptools.command.easy_install import main; main()',
57            '-mNx',
58            '-d', target_dir,
59            '--zip-ok',
60            project_dir,
61        ]
62        subprocess.check_call(args)
63        dists = pkg_resources.find_distributions(target_dir)
64        assert [dist.project_name for dist in dists] == ['my-test-package']
65        dists = pkg_resources.find_distributions(target_dir, only=True)
66        assert not list(dists)
67