test_install_cleanup.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import os
  2. from os.path import exists
  3. import pytest
  4. from pip._internal.cli.status_codes import PREVIOUS_BUILD_DIR_ERROR
  5. from pip._internal.locations import write_delete_marker_file
  6. from tests.lib import need_mercurial
  7. from tests.lib.local_repos import local_checkout
  8. def test_cleanup_after_install(script, data):
  9. """
  10. Test clean up after installing a package.
  11. """
  12. script.pip(
  13. 'install', '--no-index', '--find-links=%s' % data.find_links, 'simple'
  14. )
  15. build = script.venv_path / "build"
  16. src = script.venv_path / "src"
  17. assert not exists(build), "build/ dir still exists: %s" % build
  18. assert not exists(src), "unexpected src/ dir exists: %s" % src
  19. script.assert_no_temp()
  20. @pytest.mark.network
  21. def test_no_clean_option_blocks_cleaning_after_install(script, data):
  22. """
  23. Test --no-clean option blocks cleaning after install
  24. """
  25. build = script.base_path / 'pip-build'
  26. script.pip(
  27. 'install', '--no-clean', '--no-index', '--build', build,
  28. '--find-links=%s' % data.find_links, 'simple', expect_temp=True,
  29. )
  30. assert exists(build)
  31. @pytest.mark.network
  32. @need_mercurial
  33. def test_cleanup_after_install_editable_from_hg(script, tmpdir):
  34. """
  35. Test clean up after cloning from Mercurial.
  36. """
  37. script.pip(
  38. 'install',
  39. '-e',
  40. '%s#egg=ScriptTest' %
  41. local_checkout(
  42. 'hg+https://bitbucket.org/ianb/scripttest',
  43. tmpdir.join("cache"),
  44. ),
  45. expect_error=True,
  46. )
  47. build = script.venv_path / 'build'
  48. src = script.venv_path / 'src'
  49. assert not exists(build), "build/ dir still exists: %s" % build
  50. assert exists(src), "expected src/ dir doesn't exist: %s" % src
  51. script.assert_no_temp()
  52. def test_cleanup_after_install_from_local_directory(script, data):
  53. """
  54. Test clean up after installing from a local directory.
  55. """
  56. to_install = data.packages.join("FSPkg")
  57. script.pip('install', to_install, expect_error=False)
  58. build = script.venv_path / 'build'
  59. src = script.venv_path / 'src'
  60. assert not exists(build), "unexpected build/ dir exists: %s" % build
  61. assert not exists(src), "unexpected src/ dir exist: %s" % src
  62. script.assert_no_temp()
  63. def test_cleanup_req_satisifed_no_name(script, data):
  64. """
  65. Test cleanup when req is already satisfied, and req has no 'name'
  66. """
  67. # this test confirms Issue #420 is fixed
  68. # reqs with no 'name' that were already satisfied were leaving behind tmp
  69. # build dirs
  70. # 2 examples of reqs that would do this
  71. # 1) https://bitbucket.org/ianb/initools/get/tip.zip
  72. # 2) parent-0.1.tar.gz
  73. dist = data.packages.join("parent-0.1.tar.gz")
  74. script.pip('install', dist)
  75. script.pip('install', dist)
  76. build = script.venv_path / 'build'
  77. assert not exists(build), "unexpected build/ dir exists: %s" % build
  78. script.assert_no_temp()
  79. def test_cleanup_after_install_exception(script, data):
  80. """
  81. Test clean up after a 'setup.py install' exception.
  82. """
  83. # broken==0.2broken fails during install; see packages readme file
  84. result = script.pip(
  85. 'install', '-f', data.find_links, '--no-index', 'broken==0.2broken',
  86. expect_error=True,
  87. )
  88. build = script.venv_path / 'build'
  89. assert not exists(build), "build/ dir still exists: %s" % result.stdout
  90. script.assert_no_temp()
  91. def test_cleanup_after_egg_info_exception(script, data):
  92. """
  93. Test clean up after a 'setup.py egg_info' exception.
  94. """
  95. # brokenegginfo fails during egg_info; see packages readme file
  96. result = script.pip(
  97. 'install', '-f', data.find_links, '--no-index', 'brokenegginfo==0.1',
  98. expect_error=True,
  99. )
  100. build = script.venv_path / 'build'
  101. assert not exists(build), "build/ dir still exists: %s" % result.stdout
  102. script.assert_no_temp()
  103. @pytest.mark.network
  104. def test_cleanup_prevented_upon_build_dir_exception(script, data):
  105. """
  106. Test no cleanup occurs after a PreviousBuildDirError
  107. """
  108. build = script.venv_path / 'build'
  109. build_simple = build / 'simple'
  110. os.makedirs(build_simple)
  111. write_delete_marker_file(build_simple)
  112. build_simple.join("setup.py").write("#")
  113. result = script.pip(
  114. 'install', '-f', data.find_links, '--no-index', 'simple',
  115. '--build', build,
  116. expect_error=True, expect_temp=True,
  117. )
  118. assert result.returncode == PREVIOUS_BUILD_DIR_ERROR, str(result)
  119. assert "pip can't proceed" in result.stderr, str(result)
  120. assert exists(build_simple), str(result)