/tests/functional/test_install_cleanup.py

https://github.com/msabramo/pip · Python · 179 lines · 148 code · 14 blank · 17 comment · 0 complexity · 9762d40945b72915522f66fb7848c294 MD5 · raw file

  1. import os
  2. import pytest
  3. from os.path import exists
  4. from tests.lib.local_repos import local_checkout
  5. from tests.lib.path import Path
  6. from pip.locations import write_delete_marker_file
  7. from pip.status_codes import PREVIOUS_BUILD_DIR_ERROR
  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',
  29. )
  30. assert exists(build)
  31. @pytest.mark.network
  32. def test_cleanup_after_install_editable_from_hg(script, tmpdir):
  33. """
  34. Test clean up after cloning from Mercurial.
  35. """
  36. script.pip(
  37. 'install',
  38. '-e',
  39. '%s#egg=ScriptTest' %
  40. local_checkout(
  41. 'hg+https://bitbucket.org/ianb/scripttest',
  42. tmpdir.join("cache"),
  43. ),
  44. expect_error=True,
  45. )
  46. build = script.venv_path / 'build'
  47. src = script.venv_path / 'src'
  48. assert not exists(build), "build/ dir still exists: %s" % build
  49. assert exists(src), "expected src/ dir doesn't exist: %s" % src
  50. script.assert_no_temp()
  51. def test_cleanup_after_install_from_local_directory(script, data):
  52. """
  53. Test clean up after installing from a local directory.
  54. """
  55. to_install = data.packages.join("FSPkg")
  56. script.pip('install', to_install, expect_error=False)
  57. build = script.venv_path / 'build'
  58. src = script.venv_path / 'src'
  59. assert not exists(build), "unexpected build/ dir exists: %s" % build
  60. assert not exists(src), "unexpected src/ dir exist: %s" % src
  61. script.assert_no_temp()
  62. @pytest.mark.network
  63. def test_no_install_and_download_should_not_leave_build_dir(script):
  64. """
  65. It should remove build/ dir if it was pip that created
  66. """
  67. script.scratch_path.join("downloaded_packages").mkdir()
  68. assert not os.path.exists(script.venv_path / 'build')
  69. result = script.pip(
  70. 'install', '--no-install', 'INITools==0.2', '-d', 'downloaded_packages'
  71. )
  72. assert (
  73. Path('scratch') / 'downloaded_packages/build'
  74. not in result.files_created
  75. ), 'pip should not leave build/ dir'
  76. assert not os.path.exists(script.venv_path / 'build'), (
  77. "build/ dir should be deleted"
  78. )
  79. def test_cleanup_req_satisifed_no_name(script, data):
  80. """
  81. Test cleanup when req is already satisfied, and req has no 'name'
  82. """
  83. # this test confirms Issue #420 is fixed
  84. # reqs with no 'name' that were already satisfied were leaving behind tmp
  85. # build dirs
  86. # 2 examples of reqs that would do this
  87. # 1) https://bitbucket.org/ianb/initools/get/tip.zip
  88. # 2) parent-0.1.tar.gz
  89. dist = data.packages.join("parent-0.1.tar.gz")
  90. script.pip('install', dist)
  91. script.pip('install', dist)
  92. build = script.venv_path / 'build'
  93. assert not exists(build), "unexpected build/ dir exists: %s" % build
  94. script.assert_no_temp()
  95. @pytest.mark.network
  96. def test_download_should_not_delete_existing_build_dir(script):
  97. """
  98. It should not delete build/ if existing before run the command
  99. """
  100. script.venv_path.join("build").mkdir()
  101. script.venv_path.join("build", "somefile.txt").write("I am not empty!")
  102. script.pip('install', '--no-install', 'INITools==0.2', '-d', '.')
  103. with open(script.venv_path / 'build' / 'somefile.txt') as fp:
  104. content = fp.read()
  105. assert os.path.exists(script.venv_path / 'build'), (
  106. "build/ should be left if it exists before pip run"
  107. )
  108. assert content == 'I am not empty!', (
  109. "it should not affect build/ and its content"
  110. )
  111. assert ['somefile.txt'] == os.listdir(script.venv_path / 'build')
  112. def test_cleanup_after_install_exception(script, data):
  113. """
  114. Test clean up after a 'setup.py install' exception.
  115. """
  116. # broken==0.2broken fails during install; see packages readme file
  117. result = script.pip(
  118. 'install', '-f', data.find_links, '--no-index', 'broken==0.2broken',
  119. expect_error=True,
  120. )
  121. build = script.venv_path / 'build'
  122. assert not exists(build), "build/ dir still exists: %s" % result.stdout
  123. script.assert_no_temp()
  124. def test_cleanup_after_egg_info_exception(script, data):
  125. """
  126. Test clean up after a 'setup.py egg_info' exception.
  127. """
  128. # brokenegginfo fails during egg_info; see packages readme file
  129. result = script.pip(
  130. 'install', '-f', data.find_links, '--no-index', 'brokenegginfo==0.1',
  131. expect_error=True,
  132. )
  133. build = script.venv_path / 'build'
  134. assert not exists(build), "build/ dir still exists: %s" % result.stdout
  135. script.assert_no_temp()
  136. @pytest.mark.network
  137. def test_cleanup_prevented_upon_build_dir_exception(script, data):
  138. """
  139. Test no cleanup occurs after a PreviousBuildDirError
  140. """
  141. build = script.venv_path / 'build'
  142. build_simple = build / 'simple'
  143. os.makedirs(build_simple)
  144. write_delete_marker_file(build)
  145. build_simple.join("setup.py").write("#")
  146. result = script.pip(
  147. 'install', '-f', data.find_links, '--no-index', 'simple',
  148. '--build', build,
  149. expect_error=True,
  150. )
  151. assert result.returncode == PREVIOUS_BUILD_DIR_ERROR
  152. assert "pip can't proceed" in result.stdout, result.stdout
  153. assert exists(build_simple)