import zipfile import textwrap from os.path import abspath, exists, join from test_pip import base_path, here, reset_env, run_pip, write_file def test_cleanup_after_install_from_pypi(): """ Test clean up after installing a package from PyPI. """ reset_env() result = run_pip('install', 'INITools==0.2', expect_error=True) build = join(base_path, "build") src = join(base_path, "src") assert not exists(build), "build/ dir still exists: %s" % build assert not exists(src), "unexpected src/ dir exists: %s" % src def test_cleanup_after_install_editable_from_hg(): """ Test clean up after cloning from Mercurial. """ reset_env() result = run_pip('install', '-e', 'hg+http://bitbucket.org/ubernostrum/django-registration/#egg=django-registration', expect_error=True) build = join(base_path, "build") src = join(base_path, "src") assert not exists(build), "build/ dir still exists: %s" % build assert exists(src), "expected src/ dir doesn't exist: %s" % src def test_cleanup_after_install_from_local_directory(): """ Test clean up after installing from a local directory. """ reset_env() to_install = abspath(join(here, 'packages', 'FSPkg')) result = run_pip('install', to_install, expect_error=False) build = join(base_path, "build") src = join(base_path, "src") assert not exists(build), "unexpected build/ dir exists: %s" % build assert not exists(src), "unexpected src/ dir exist: %s" % src def test_cleanup_after_create_bundle(): """ Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/. """ reset_env() # Install an editable to create a src/ dir. dummy = run_pip('install', '-e', 'git://github.com/jezdez/django-feedutil.git#egg=django-feedutil') build = join(base_path, "build") src = join(base_path, "src") assert not exists(build), "build/ dir still exists: %s" % build assert exists(src), "expected src/ dir doesn't exist: %s" % src # Make the bundle. fspkg = 'file://%s/FSPkg' %join(here, 'packages') pkg_lines = textwrap.dedent('''\ -e %s -e svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev pip''' % fspkg) write_file('bundle-req.txt', pkg_lines) result = run_pip('bundle', '-r', 'bundle-req.txt', 'test.pybundle') build_bundle = join(base_path, "build-bundle") src_bundle = join(base_path, "src-bundle") assert not exists(build_bundle), "build-bundle/ dir still exists: %s" % build_bundle assert not exists(src_bundle), "src-bundle/ dir still exists: %s" % src_bundle # Make sure previously created src/ from editable still exists assert exists(src), "expected src dir doesn't exist: %s" % src