• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3import sys
4import os
5import shutil
6import tempfile
7import subprocess
8from distutils.command.install import INSTALL_SCHEMES
9from string import Template
10
11from six.moves import urllib
12
13
14def _system_call(*args):
15    assert subprocess.call(args) == 0
16
17
18def tempdir(func):
19    def _tempdir(*args, **kwargs):
20        test_dir = tempfile.mkdtemp()
21        old_dir = os.getcwd()
22        os.chdir(test_dir)
23        try:
24            return func(*args, **kwargs)
25        finally:
26            os.chdir(old_dir)
27            shutil.rmtree(test_dir)
28
29    return _tempdir
30
31
32SIMPLE_BUILDOUT = """\
33[buildout]
34
35parts = eggs
36
37[eggs]
38recipe = zc.recipe.egg
39
40eggs =
41    extensions
42"""
43
44BOOTSTRAP = 'http://downloads.buildout.org/1/bootstrap.py'
45PYVER = sys.version.split()[0][:3]
46
47_VARS = {'base': '.',
48         'py_version_short': PYVER}
49
50scheme = 'nt' if sys.platform == 'win32' else 'unix_prefix'
51PURELIB = INSTALL_SCHEMES[scheme]['purelib']
52
53
54@tempdir
55def test_virtualenv():
56    """virtualenv with setuptools"""
57    purelib = os.path.abspath(Template(PURELIB).substitute(**_VARS))
58    _system_call('virtualenv', '--no-site-packages', '.')
59    _system_call('bin/easy_install', 'setuptools==dev')
60    # linux specific
61    site_pkg = os.listdir(purelib)
62    site_pkg.sort()
63    assert 'setuptools' in site_pkg[0]
64    easy_install = os.path.join(purelib, 'easy-install.pth')
65    with open(easy_install) as f:
66        res = f.read()
67    assert 'setuptools' in res
68
69
70@tempdir
71def test_full():
72    """virtualenv + pip + buildout"""
73    _system_call('virtualenv', '--no-site-packages', '.')
74    _system_call('bin/easy_install', '-q', 'setuptools==dev')
75    _system_call('bin/easy_install', '-qU', 'setuptools==dev')
76    _system_call('bin/easy_install', '-q', 'pip')
77    _system_call('bin/pip', 'install', '-q', 'zc.buildout')
78
79    with open('buildout.cfg', 'w') as f:
80        f.write(SIMPLE_BUILDOUT)
81
82    with open('bootstrap.py', 'w') as f:
83        f.write(urllib.request.urlopen(BOOTSTRAP).read())
84
85    _system_call('bin/python', 'bootstrap.py')
86    _system_call('bin/buildout', '-q')
87    eggs = os.listdir('eggs')
88    eggs.sort()
89    assert len(eggs) == 3
90    assert eggs[1].startswith('setuptools')
91    del eggs[1]
92    assert eggs == ['extensions-0.3-py2.6.egg',
93        'zc.recipe.egg-1.2.2-py2.6.egg']
94
95
96if __name__ == '__main__':
97    test_virtualenv()
98    test_full()
99