test_integration.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. """Run some integration tests.
  2. Try to install a few packages.
  3. """
  4. import glob
  5. import os
  6. import sys
  7. import pytest
  8. from setuptools.command.easy_install import easy_install
  9. from setuptools.command import easy_install as easy_install_pkg
  10. from setuptools.dist import Distribution
  11. from setuptools.compat import urlopen
  12. def setup_module(module):
  13. packages = 'stevedore', 'virtualenvwrapper', 'pbr', 'novaclient'
  14. for pkg in packages:
  15. try:
  16. __import__(pkg)
  17. tmpl = "Integration tests cannot run when {pkg} is installed"
  18. pytest.skip(tmpl.format(**locals()))
  19. except ImportError:
  20. pass
  21. try:
  22. urlopen('https://pypi.python.org/pypi')
  23. except Exception as exc:
  24. pytest.skip(reason=str(exc))
  25. @pytest.fixture
  26. def install_context(request, tmpdir, monkeypatch):
  27. """Fixture to set up temporary installation directory.
  28. """
  29. # Save old values so we can restore them.
  30. new_cwd = tmpdir.mkdir('cwd')
  31. user_base = tmpdir.mkdir('user_base')
  32. user_site = tmpdir.mkdir('user_site')
  33. install_dir = tmpdir.mkdir('install_dir')
  34. def fin():
  35. # undo the monkeypatch, particularly needed under
  36. # windows because of kept handle on cwd
  37. monkeypatch.undo()
  38. new_cwd.remove()
  39. user_base.remove()
  40. user_site.remove()
  41. install_dir.remove()
  42. request.addfinalizer(fin)
  43. # Change the environment and site settings to control where the
  44. # files are installed and ensure we do not overwrite anything.
  45. monkeypatch.chdir(new_cwd)
  46. monkeypatch.setattr(easy_install_pkg, '__file__', user_site.strpath)
  47. monkeypatch.setattr('site.USER_BASE', user_base.strpath)
  48. monkeypatch.setattr('site.USER_SITE', user_site.strpath)
  49. monkeypatch.setattr('sys.path', sys.path + [install_dir.strpath])
  50. monkeypatch.setenv('PYTHONPATH', os.path.pathsep.join(sys.path))
  51. # Set up the command for performing the installation.
  52. dist = Distribution()
  53. cmd = easy_install(dist)
  54. cmd.install_dir = install_dir.strpath
  55. return cmd
  56. def _install_one(requirement, cmd, pkgname, modulename):
  57. cmd.args = [requirement]
  58. cmd.ensure_finalized()
  59. cmd.run()
  60. target = cmd.install_dir
  61. dest_path = glob.glob(os.path.join(target, pkgname + '*.egg'))
  62. assert dest_path
  63. assert os.path.exists(os.path.join(dest_path[0], pkgname, modulename))
  64. def test_stevedore(install_context):
  65. _install_one('stevedore', install_context,
  66. 'stevedore', 'extension.py')
  67. @pytest.mark.xfail
  68. def test_virtualenvwrapper(install_context):
  69. _install_one('virtualenvwrapper', install_context,
  70. 'virtualenvwrapper', 'hook_loader.py')
  71. def test_pbr(install_context):
  72. _install_one('pbr', install_context,
  73. 'pbr', 'core.py')
  74. @pytest.mark.xfail
  75. def test_python_novaclient(install_context):
  76. _install_one('python-novaclient', install_context,
  77. 'novaclient', 'base.py')