1
- import subprocess
2
- import sys
3
-
1
+ import py
4
2
import pytest
5
3
import pkg_resources
6
4
7
- SETUP_TEMPLATE = """
8
- import setuptools
9
- setuptools.setup(
10
- name="my-test-package",
11
- version="1.0",
12
- zip_safe=True,
13
- )
14
- """ .lstrip ()
5
+
6
+ TESTS_DATA_DIR = py .path .local (__file__ ).dirpath ('data' )
15
7
16
8
17
9
class TestFindDistributions :
@@ -21,46 +13,22 @@ def target_dir(self, tmpdir):
21
13
target_dir = tmpdir .mkdir ('target' )
22
14
# place a .egg named directory in the target that is not an egg:
23
15
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 )
16
+ return target_dir
31
17
32
18
def test_non_egg_dir_named_egg (self , target_dir ):
33
- dists = pkg_resources .find_distributions (target_dir )
19
+ dists = pkg_resources .find_distributions (str ( target_dir ) )
34
20
assert not list (dists )
35
21
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 )
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 ))
48
25
assert [dist .project_name for dist in dists ] == ['my-test-package' ]
49
- dists = pkg_resources .find_distributions (target_dir , only = True )
26
+ dists = pkg_resources .find_distributions (str ( target_dir ) , only = True )
50
27
assert not list (dists )
51
28
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 )
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 ))
64
32
assert [dist .project_name for dist in dists ] == ['my-test-package' ]
65
- dists = pkg_resources .find_distributions (target_dir , only = True )
33
+ dists = pkg_resources .find_distributions (str ( target_dir ) , only = True )
66
34
assert not list (dists )
0 commit comments