summaryrefslogtreecommitdiff
path: root/tests/test_basic.py
blob: f1d9112066a9ccdc81ce73ad1fa09a502bbb533a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from os.path import abspath, join, dirname, curdir, pardir
from test_pip import here, reset_env, run_pip, pyversion, lib_py, mkdir

def test_correct_pip_version():
    """
    Check we are running proper version of pip in run_pip.
    
    """
    reset_env()

    # where this source distribution lives
    base = abspath(join(dirname(__file__), pardir))

    # output will contain the directory of the invoked pip
    result = run_pip('--version')

    # compare the directory tree of the invoked pip with that of this source distribution
    import re,filecmp
    dir = re.match(r'\s*pip\s\S+\sfrom\s+(.*)\s\([^(]+\)$', result.stdout).group(1)
    diffs = filecmp.dircmp(join(base,'pip'), join(dir,'pip'))

    # If any non-matching .py files exist, we have a problem: run_pip
    # is picking up some other version!  N.B. if this project acquires
    # primary resources other than .py files, this code will need
    # maintenance
    mismatch_py = [x for x in diffs.left_only + diffs.right_only + diffs.diff_files if x.endswith('.py')]
    assert not mismatch_py, 'mismatched source files in %r and %r'% (join(base,'pip'), join(dir,'pip'))

def test_distutils_configuration_setting():
    """
    Test the distutils-configuration-setting command (which is distinct from other commands).
    
    """
    #print run_pip('-vv', '--distutils-cfg=easy_install:index_url:http://download.zope.org/ppix/', expect_error=True)
    #Script result: python ../../poacheggs.py -E .../poacheggs-tests/test-scratch -vv --distutils-cfg=easy_install:index_url:http://download.zope.org/ppix/
    #-- stdout: --------------------
    #Distutils config .../poacheggs-tests/test-scratch/lib/python.../distutils/distutils.cfg is writable
    #Replaced setting index_url
    #Updated .../poacheggs-tests/test-scratch/lib/python.../distutils/distutils.cfg
    #<BLANKLINE>
    #-- updated: -------------------
    #  lib/python2.4/distutils/distutils.cfg  (346 bytes)

def test_install_from_pypi():
    """
    Test installing a package from PyPI.
    
    """
    reset_env()
    result = run_pip('install', '-vvv', 'INITools==0.2', expect_error=True)
    assert (lib_py + 'site-packages/INITools-0.2-py%s.egg-info' % pyversion) in result.files_created, str(result)
    assert (lib_py + 'site-packages/initools') in result.files_created, sorted(result.files_created.keys())

def test_editable_install():
    """
    Test editable installation.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'INITools==0.2', expect_error=True)
    assert "--editable=INITools==0.2 should be formatted with svn+URL" in result.stdout
    assert len(result.files_created) == 1, result.files_created
    assert not result.files_updated, result.files_updated

def test_install_editable_from_svn():
    """
    Test checking out from svn.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev', expect_error=True)
    egg_link = result.files_created[lib_py + 'site-packages/INITools.egg-link']
    # FIXME: I don't understand why there's a trailing . here:
    assert egg_link.bytes.endswith('/test-scratch/src/initools\n.'), egg_link.bytes
    assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
    assert 'src/initools' in result.files_created
    assert 'src/initools/.svn' in result.files_created

def test_download_editable_to_custom_path():
    """
    Test downloading an editable using a relative custom src folder.
    
    """
    reset_env()
    mkdir('customdl')
    result = run_pip('install', '-e', 'svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev',
        '--src', 'customsrc', '--download', 'customdl',
        expect_error=True)
    assert 'customsrc/initools' in result.files_created
    assert 'customsrc/initools/setup.py' in result.files_created
    assert [filename for filename in result.files_created.keys() if filename.startswith('customdl/initools')]

def test_editable_no_install_followed_by_no_download():
    """
    Test installing an editable in two steps (first with --no-install, then with --no-download).
    
    """
    reset_env()

    result = run_pip('install', '-e', 'svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev',
        '--no-install', expect_error=True)
    assert lib_py + 'site-packages/INITools.egg-link' not in result.files_created
    assert 'src/initools' in result.files_created
    assert 'src/initools/.svn' in result.files_created

    result = run_pip('install', '-e', 'svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev',
        '--no-download',  expect_error=True)
    egg_link = result.files_created[lib_py + 'site-packages/INITools.egg-link']
    # FIXME: I don't understand why there's a trailing . here:
    assert egg_link.bytes.endswith('/test-scratch/src/initools\n.'), egg_link.bytes
    assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
    assert 'src/initools' not in result.files_created
    assert 'src/initools/.svn' not in result.files_created

def test_no_install_followed_by_no_download():
    """
    Test installing in two steps (first with --no-install, then with --no-download).
    
    """
    reset_env()

    result = run_pip('install', 'INITools==0.2', '--no-install', expect_error=True)
    assert (lib_py + 'site-packages/INITools-0.2-py%s.egg-info' % pyversion) not in result.files_created, str(result)
    assert (lib_py + 'site-packages/initools') not in result.files_created, sorted(result.files_created.keys())
    assert 'build/INITools' in result.files_created
    assert 'build/INITools/INITools.egg-info' in result.files_created

    result = run_pip('install', 'INITools==0.2', '--no-download',  expect_error=True)
    assert (lib_py + 'site-packages/INITools-0.2-py%s.egg-info' % pyversion) in result.files_created, str(result)
    assert (lib_py + 'site-packages/initools') in result.files_created, sorted(result.files_created.keys())
    assert 'build/INITools' not in result.files_created
    assert 'build/INITools/INITools.egg-info' not in result.files_created

def test_install_dev_version_from_pypi():
    """
    Test using package==dev.
    
    """
    reset_env()
    result = run_pip('install', 'INITools==dev', expect_error=True)
    assert (lib_py + 'site-packages/initools') in result.files_created, str(result.stdout)

def test_install_editable_from_git():
    """
    Test cloning from Git.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'git://github.com/jezdez/django-feedutil.git#egg=django-feedutil', expect_error=True)
    egg_link = result.files_created[lib_py + 'site-packages/django-feedutil.egg-link']
    # FIXME: I don't understand why there's a trailing . here:
    assert egg_link.bytes.endswith('/test-scratch/src/django-feedutil\n.'), egg_link.bytes
    assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
    assert 'src/django-feedutil' in result.files_created
    assert 'src/django-feedutil/.git' in result.files_created

def test_install_editable_from_hg():
    """
    Test cloning from Mercurial.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'hg+http://bitbucket.org/ubernostrum/django-registration/#egg=django-registration', expect_error=True)
    egg_link = result.files_created[lib_py + 'site-packages/django-registration.egg-link']
    # FIXME: I don't understand why there's a trailing . here:
    assert egg_link.bytes.endswith('/test-scratch/src/django-registration\n.'), egg_link.bytes
    assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
    assert 'src/django-registration' in result.files_created
    assert 'src/django-registration/.hg' in result.files_created

def test_vcs_url_final_slash_normalization():
    """
    Test that presence or absence of final slash in VCS URL is normalized.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'hg+http://bitbucket.org/ubernostrum/django-registration#egg=django-registration', expect_error=True)
    assert 'pip-log.txt' not in result.files_created, result.files_created['pip-log.txt'].bytes

def test_install_editable_from_bazaar():
    """
    Test checking out from Bazaar.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1/@174#egg=django-wikiapp', expect_error=True)
    egg_link = result.files_created[lib_py + 'site-packages/django-wikiapp.egg-link']
    # FIXME: I don't understand why there's a trailing . here:
    assert egg_link.bytes.endswith('/test-scratch/src/django-wikiapp\n.'), egg_link.bytes
    assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
    assert 'src/django-wikiapp' in result.files_created
    assert 'src/django-wikiapp/.bzr' in result.files_created

def test_vcs_url_urlquote_normalization():
    """
    Test that urlquoted characters are normalized for repo URL comparison.
    
    """
    reset_env()
    result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/~django-wikiapp/django-wikiapp/release-0.1#egg=django-wikiapp', expect_error=True)
    assert 'pip-log.txt' not in result.files_created, result.files_created['pip-log.txt'].bytes

def test_install_from_local_directory():
    """
    Test installing from a local directory.

    """
    reset_env()
    to_install = abspath(join(here, 'packages', 'FSPkg'))
    result = run_pip('install', to_install, expect_error=False)
    assert (lib_py + 'site-packages/fspkg') in result.files_created, str(result.stdout)
    assert (lib_py + 'site-packages/FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)

def test_install_from_local_directory_with_no_setup_py():
    """
    Test installing from a local directory with no 'setup.py'.

    """
    reset_env()
    result = run_pip('install', here, expect_error=True)
    assert len(result.files_created) == 1, result.files_created
    assert 'pip-log.txt' in result.files_created, result.files_created
    assert "is not installable. File 'setup.py' not found." in result.stdout

def test_install_curdir():
    """
    Test installing current directory ('.').

    """
    reset_env()
    run_from = abspath(join(here, 'packages', 'FSPkg'))
    result = run_pip('install', curdir, cwd=run_from, expect_error=False)
    assert (lib_py + 'site-packages/fspkg') in result.files_created, str(result.stdout)
    assert (lib_py + 'site-packages/FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)

def test_install_pardir():
    """
    Test installing parent directory ('..').

    """
    reset_env()
    run_from = abspath(join(here, 'packages', 'FSPkg', 'fspkg'))
    result = run_pip('install', pardir, cwd=run_from, expect_error=False)
    assert (lib_py + 'site-packages/fspkg') in result.files_created, str(result.stdout)
    assert (lib_py + 'site-packages/FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)