manual_test.py 2.3 KB

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