1import py 2import pytest 3import pkg_resources 4 5 6TESTS_DATA_DIR = py.path.local(__file__).dirpath('data') 7 8 9class TestFindDistributions: 10 11 @pytest.fixture 12 def target_dir(self, tmpdir): 13 target_dir = tmpdir.mkdir('target') 14 # place a .egg named directory in the target that is not an egg: 15 target_dir.mkdir('not.an.egg') 16 return target_dir 17 18 def test_non_egg_dir_named_egg(self, target_dir): 19 dists = pkg_resources.find_distributions(str(target_dir)) 20 assert not list(dists) 21 22 def test_standalone_egg_directory(self, target_dir): 23 (TESTS_DATA_DIR / 'my-test-package_unpacked-egg').copy(target_dir) 24 dists = pkg_resources.find_distributions(str(target_dir)) 25 assert [dist.project_name for dist in dists] == ['my-test-package'] 26 dists = pkg_resources.find_distributions(str(target_dir), only=True) 27 assert not list(dists) 28 29 def test_zipped_egg(self, target_dir): 30 (TESTS_DATA_DIR / 'my-test-package_zipped-egg').copy(target_dir) 31 dists = pkg_resources.find_distributions(str(target_dir)) 32 assert [dist.project_name for dist in dists] == ['my-test-package'] 33 dists = pkg_resources.find_distributions(str(target_dir), only=True) 34 assert not list(dists) 35 36 def test_zipped_sdist_one_level_removed(self, target_dir): 37 (TESTS_DATA_DIR / 'my-test-package-zip').copy(target_dir) 38 dists = pkg_resources.find_distributions( 39 str(target_dir / "my-test-package.zip")) 40 assert [dist.project_name for dist in dists] == ['my-test-package'] 41 dists = pkg_resources.find_distributions( 42 str(target_dir / "my-test-package.zip"), only=True) 43 assert not list(dists) 44