def test_pip_wheel_ignore_wheels_editables(): """ Test 'pip wheel' ignores editables and *.whl files in requirements """ env = reset_env() pip_install_local('wheel') local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % find_links local_editable = os.path.abspath( os.path.join(tests_data, 'packages', 'FSPkg')) write_file( 'reqs.txt', textwrap.dedent("""\ %s -e %s simple """ % (local_wheel, local_editable))) result = run_pip('wheel', '--no-index', '-f', find_links, '-r', env.scratch_path / 'reqs.txt') wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot wheel_file_path = env.scratch / 'wheelhouse' / wheel_file_name assert wheel_file_path in result.files_created, (wheel_file_path, result.files_created) assert "Successfully built simple" in result.stdout, result.stdout assert "Failed to build" not in result.stdout, result.stdout assert "ignoring %s" % local_wheel in result.stdout ignore_editable = "ignoring %s" % path_to_url(local_editable) #TODO: understand this divergence if sys.platform == 'win32': ignore_editable = "ignoring %s" % path_to_url_d(local_editable) assert ignore_editable in result.stdout, result.stdout
def test_upgrade_from_reqs_file(): """ Upgrade from a requirements file. """ env = reset_env() write_file( "test-req.txt", textwrap.dedent( """\ PyLogo<0.4 # and something else to test out: INITools==0.3 """ ), ) install_result = run_pip("install", "-r", env.scratch_path / "test-req.txt") write_file( "test-req.txt", textwrap.dedent( """\ PyLogo # and something else to test out: INITools """ ), ) run_pip("install", "--upgrade", "-r", env.scratch_path / "test-req.txt") uninstall_result = run_pip("uninstall", "-r", env.scratch_path / "test-req.txt", "-y") assert_all_changes(install_result, uninstall_result, [env.venv / "build", "cache", env.scratch / "test-req.txt"])
def test_uninstall_from_reqs_file(): """ Test uninstall from a requirements file. """ env = reset_env() write_file( 'test-req.txt', textwrap.dedent("""\ -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result = run_pip('install', '-r', 'test-req.txt') write_file( 'test-req.txt', textwrap.dedent("""\ # -f, -i, and --extra-index-url should all be ignored by uninstall -f http://www.example.com -i http://www.example.com --extra-index-url http://www.example.com -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y') assert_all_changes( result, result2, [env.venv / 'build', env.venv / 'src', env.scratch / 'test-req.txt'])
def test_uninstall_from_reqs_file(): """ Test uninstall from a requirements file. """ env = reset_env() write_file('test-req.txt', textwrap.dedent("""\ -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result = run_pip('install', '-r', 'test-req.txt') write_file('test-req.txt', textwrap.dedent("""\ # -f, -i, and --extra-index-url should all be ignored by uninstall -f http://www.example.com -i http://www.example.com --extra-index-url http://www.example.com -e %s#egg=initools-dev # and something else to test out: PyLogo<0.4 """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y') assert_all_changes( result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
def _change_test_package_submodule(env, submodule_path): write_file(submodule_path/'testfile', 'this is a changed file') write_file(submodule_path/'testfile2', 'this is an added file') env.run('git', 'add', '.', cwd=submodule_path) env.run('git', 'commit', '-q', '--author', 'Pip <*****@*****.**>', '-am', 'submodule change', cwd=submodule_path)
def test_freeze_basic(): """ Some tests of freeze, first we have to install some stuff. Note that the test is a little crude at the end because Python 2.5+ adds egg info to the standard library, so stuff like wsgiref will show up in the freezing. (Probably that should be accounted for in pip, but currently it is not). """ env = reset_env() write_file( 'initools-req.txt', textwrap.dedent("""\ simple==2.0 # and something else to test out: simple2<=3.0 """)) result = pip_install_local('-r', env.scratch_path / 'initools-req.txt') result = run_pip('freeze', expect_stderr=True) expected = textwrap.dedent("""\ Script result: pip freeze -- stdout: -------------------- ...simple==2.0 simple2==3.0... <BLANKLINE>""") _check_output(result, expected)
def test_pip_wheel_ignore_wheels_editables(): """ Test 'pip wheel' ignores editables and *.whl files in requirements """ env = reset_env() pip_install_local('wheel') local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % find_links local_editable = os.path.abspath(os.path.join(tests_data, 'packages', 'FSPkg')) write_file('reqs.txt', textwrap.dedent("""\ %s -e %s simple """ % (local_wheel, local_editable))) result = run_pip('wheel', '--no-index', '-f', find_links, '-r', env.scratch_path / 'reqs.txt') wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot wheel_file_path = env.scratch/'wheelhouse'/wheel_file_name assert wheel_file_path in result.files_created, (wheel_file_path, result.files_created) assert "Successfully built simple" in result.stdout, result.stdout assert "Failed to build" not in result.stdout, result.stdout assert "ignoring %s" % local_wheel in result.stdout ignore_editable = "ignoring %s" % path_to_url(local_editable) #TODO: understand this divergence if sys.platform == 'win32': ignore_editable = "ignoring %s" % path_to_url_d(local_editable) assert ignore_editable in result.stdout, result.stdout
def test_upgrade_from_reqs_file(): """ Upgrade from a requirements file. """ env = reset_env() write_file( 'test-req.txt', textwrap.dedent("""\ PyLogo<0.4 # and something else to test out: INITools==0.3 """)) install_result = run_pip('install', '-r', env.scratch_path / 'test-req.txt') write_file( 'test-req.txt', textwrap.dedent("""\ PyLogo # and something else to test out: INITools """)) run_pip('install', '--upgrade', '-r', env.scratch_path / 'test-req.txt') uninstall_result = run_pip('uninstall', '-r', env.scratch_path / 'test-req.txt', '-y') assert_all_changes( install_result, uninstall_result, [env.venv / 'build', 'cache', env.scratch / 'test-req.txt'])
def _test_config_file_override_stack(config_file): environ = clear_environ(os.environ.copy()) environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it reset_env(environ) write_file( config_file, textwrap.dedent("""\ [global] index-url = http://download.zope.org/ppix """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Getting page http://download.zope.org/ppix/INITools" in result.stdout reset_env(environ) write_file( config_file, textwrap.dedent("""\ [global] index-url = http://download.zope.org/ppix [install] index-url = http://pypi.appspot.com/ """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Getting page http://pypi.appspot.com/INITools" in result.stdout result = run_pip('install', '-vvv', '--index-url', 'http://pypi.python.org/simple', 'INITools', expect_error=True) assert "Getting page http://download.zope.org/ppix/INITools" not in result.stdout assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout assert "Getting page http://pypi.python.org/simple/INITools" in result.stdout
def test_create_bundle(): """ Test making a bundle. We'll grab one package from the filesystem (the FSPkg dummy package), one from vcs (initools) and one from an index (pip itself). """ env = reset_env() fspkg = path_to_url2(Path(tests_data) / 'packages' / 'FSPkg') run_pip('install', '-e', fspkg) pkg_lines = textwrap.dedent( '''\ -e %s -e %s#egg=initools-dev pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) write_file('bundle-req.txt', pkg_lines) # Create a bundle in env.scratch_path/ test.pybundle result = run_pip('bundle', '-r', env.scratch_path / 'bundle-req.txt', env.scratch_path / 'test.pybundle') bundle = result.files_after.get(join('scratch', 'test.pybundle'), None) assert bundle is not None files = zipfile.ZipFile(bundle.full).namelist() assert 'src/FSPkg/' in files assert 'src/initools/' in files assert 'build/pip/' in files
def test_freeze_with_requirement_option(): """ Test that new requirements are created correctly with --requirement hints """ reset_env() ignores = textwrap.dedent("""\ # Unchanged requirements below this line -r ignore.txt --requirement ignore.txt -Z ignore --always-unzip ignore -f http://ignore -i http://ignore --extra-index-url http://ignore --find-links http://ignore --index-url http://ignore """) write_file('hint.txt', textwrap.dedent("""\ INITools==0.1 NoExist==4.2 """) + ignores) result = run_pip('install', 'initools==0.2') result = pip_install_local('simple') result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True) expected = textwrap.dedent("""\ Script result: pip freeze --requirement hint.txt -- stderr: -------------------- Requirement file contains NoExist==4.2, but that package is not installed -- stdout: -------------------- INITools==0.2 """) + ignores + "## The following requirements were added by pip --freeze:..." _check_output(result, expected)
def test_download_should_skip_existing_files(): """ It should not download files already existing in the scratch dir """ env = reset_env() write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 """)) result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages/ 'initools' not in result.files_created # adding second package to test-req.txt write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 python-openid==2.2.5 """)) # only the second package should be downloaded result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) openid_tarball_prefix = str(Path('scratch')/ 'python-openid-') assert any(path.startswith(openid_tarball_prefix) for path in result.files_created) assert Path('scratch')/ 'INITools-0.1.tar.gz' not in result.files_created assert env.site_packages/ 'initools' not in result.files_created assert env.site_packages/ 'openid' not in result.files_created
def test_cleanup_after_create_bundle(): """ Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/. """ env = reset_env() # Install an editable to create a src/ dir. args = ['install'] args.extend(['-e', '%s#egg=pip-test-package' % local_checkout('git+http://github.com/pypa/pip-test-package.git')]) run_pip(*args) build = env.venv_path/"build" src = env.venv_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(tests_data, 'packages') pkg_lines = textwrap.dedent('''\ -e %s -e %s#egg=initools-dev pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) write_file('bundle-req.txt', pkg_lines) run_pip('bundle', '-r', 'bundle-req.txt', 'test.pybundle') build_bundle = env.scratch_path/"build-bundle" src_bundle = env.scratch_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 env.assert_no_temp() # Make sure previously created src/ from editable still exists assert exists(src), "expected src dir doesn't exist: %s" % src
def test_schema_check_in_requirements_file(): """ Test installing from a requirements file with an invalid vcs schema.. """ env = reset_env() write_file('file-egg-req.txt', textwrap.dedent("""\ git://github.com/alex/django-fixture-generator.git#egg=fixture_generator """)) assert_raises(AssertionError, run_pip, 'install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
def test_cleanup_prevented_upon_build_dir_exception(): """ Test no cleanup occurs after a PreviousBuildDirError """ env = reset_env() build = env.venv_path/'build'/'simple' os.makedirs(build) write_file("setup.py", "#", dest=build) result = run_pip('install', '-f', find_links, '--no-index', 'simple', expect_error=True) assert "pip can't proceed" in result.stdout, result.stdout assert exists(build)
def test_install_folder_using_slash_in_the_end(): r""" Test installing a folder using pip install foldername/ or foldername\ """ env = reset_env() mkdir('mock') pkg_path = env.scratch_path/'mock' write_file('setup.py', mock100_setup_py, pkg_path) result = run_pip('install', 'mock' + os.path.sep) egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion assert egg_folder in result.files_created, str(result)
def test_install_folder_using_slash_in_the_end(): r""" Test installing a folder using pip install foldername/ or foldername\ """ env = reset_env() mkdir('mock') pkg_path = env.scratch_path / 'mock' write_file('setup.py', mock100_setup_py, pkg_path) result = run_pip('install', 'mock' + os.path.sep) egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion assert egg_folder in result.files_created, str(result)
def test_single_download_from_requirements_file(): """ It should support download (in the scratch path) from PyPi from a requirements file """ env = reset_env() write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 """)) result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True) assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages/ 'initools' not in result.files_created
def test_install_folder_using_relative_path(): """ Test installing a folder using pip install folder1/folder2 """ env = reset_env() mkdir('initools') mkdir(Path('initools')/'mock') pkg_path = env.scratch_path/'initools'/'mock' write_file('setup.py', mock100_setup_py, pkg_path) result = run_pip('install', Path('initools')/'mock') egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion assert egg_folder in result.files_created, str(result)
def _change_test_package_submodule(env, submodule_path): write_file(submodule_path / 'testfile', 'this is a changed file') write_file(submodule_path / 'testfile2', 'this is an added file') env.run('git', 'add', '.', cwd=submodule_path) env.run('git', 'commit', '-q', '--author', 'Pip <*****@*****.**>', '-am', 'submodule change', cwd=submodule_path)
def test_install_folder_using_relative_path(): """ Test installing a folder using pip install folder1/folder2 """ env = reset_env() mkdir('initools') mkdir(Path('initools') / 'mock') pkg_path = env.scratch_path / 'initools' / 'mock' write_file('setup.py', mock100_setup_py, pkg_path) result = run_pip('install', Path('initools') / 'mock') egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion assert egg_folder in result.files_created, str(result)
def test_relative_requirements_file(): """ Test installing from a requirements file with a relative path with an egg= definition.. """ url = path_to_url(os.path.join(tests_data, 'packages', '..', 'packages', 'FSPkg')) + '#egg=FSPkg' env = reset_env() write_file('file-egg-req.txt', textwrap.dedent("""\ %s """ % url)) result = run_pip('install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt') assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result) assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
def test_find_command_folder_in_path(): """ If a folder named e.g. 'git' is in PATH, and find_command is looking for the 'git' executable, it should not match the folder, but rather keep looking. """ env = reset_env() mkdir('path_one') path_one = env.scratch_path / 'path_one' mkdir(path_one / 'foo') mkdir('path_two') path_two = env.scratch_path / 'path_two' write_file(path_two / 'foo', '# nothing') found_path = find_command('foo', map(str, [path_one, path_two])) assert found_path == path_two / 'foo'
def test_find_command_folder_in_path(): """ If a folder named e.g. 'git' is in PATH, and find_command is looking for the 'git' executable, it should not match the folder, but rather keep looking. """ env = reset_env() mkdir('path_one') path_one = env.scratch_path/'path_one' mkdir(path_one/'foo') mkdir('path_two') path_two = env.scratch_path/'path_two' write_file(path_two/'foo', '# nothing') found_path = find_command('foo', map(str, [path_one, path_two])) assert found_path == path_two/'foo'
def test_cleanup_prevented_upon_build_dir_exception(): """ Test no cleanup occurs after a PreviousBuildDirError """ env = reset_env() build = env.venv_path / 'build' / 'simple' os.makedirs(build) write_file("setup.py", "#", dest=build) result = run_pip('install', '-f', find_links, '--no-index', 'simple', expect_error=True) assert "pip can't proceed" in result.stdout, result.stdout assert exists(build)
def test_find_links_requirements_file_relative_path(): """Test find-links as a relative path to a reqs file.""" e = reset_env() write_file('test-req.txt', textwrap.dedent(""" --no-index --find-links=../../../data/packages/ parent==0.1 """)) result = run_pip( 'install', '-r', e.scratch_path / "test-req.txt", cwd=tests_data) egg_info_folder = e.site_packages / 'parent-0.1-py%s.egg-info' % pyversion initools_folder = e.site_packages / 'parent' assert egg_info_folder in result.files_created, str(result) assert initools_folder in result.files_created, str(result)
def test_single_download_from_requirements_file(): """ It should support download (in the scratch path) from PyPi from a requirements file """ env = reset_env() write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 """)) result = run_pip('install', '-r', env.scratch_path / 'test-req.txt', '-d', '.', expect_error=True) assert Path('scratch') / 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages / 'initools' not in result.files_created
def _test_env_vars_override_config_file(config_file): environ = clear_environ(os.environ.copy()) environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it reset_env(environ) # It's important that we test this particular config value ('no-index') # because their is/was a bug which only shows up in cases in which # 'config-item' and 'config_item' hash to the same value modulo the size # of the config dictionary. write_file(config_file, textwrap.dedent("""\ [global] no-index = 1 """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "DistributionNotFound: No distributions at all found for INITools" in result.stdout environ['PIP_NO_INDEX'] = '0' reset_env(environ) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Successfully installed INITools" in result.stdout
def test_requirements_file(): """ Test installing from a requirements file. """ other_lib_name, other_lib_version = 'anyjson', '0.3' env = reset_env() write_file('initools-req.txt', textwrap.dedent("""\ INITools==0.2 # and something else to test out: %s<=%s """ % (other_lib_name, other_lib_version))) result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt') assert env.site_packages/'INITools-0.2-py%s.egg-info' % pyversion in result.files_created assert env.site_packages/'initools' in result.files_created assert result.files_created[env.site_packages/other_lib_name].dir fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion) assert result.files_created[env.site_packages/fn].dir
def test_multiple_requirements_files(): """ Test installing from multiple nested requirements files. """ other_lib_name, other_lib_version = 'anyjson', '0.3' env = reset_env() write_file('initools-req.txt', textwrap.dedent("""\ -e %s@10#egg=INITools-dev -r %s-req.txt""" % (local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'), other_lib_name))) write_file('%s-req.txt' % other_lib_name, textwrap.dedent("""\ %s<=%s """ % (other_lib_name, other_lib_version))) result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt') assert result.files_created[env.site_packages/other_lib_name].dir fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion) assert result.files_created[env.site_packages/fn].dir assert env.venv/'src'/'initools' in result.files_created
def test_respect_order_in_requirements_file(): env = reset_env() write_file('frameworks-req.txt', textwrap.dedent("""\ parent child simple """)) result = run_pip('install', '--no-index', '-f', find_links, '-r', env.scratch_path / 'frameworks-req.txt') downloaded = [line for line in result.stdout.split('\n') if 'Downloading/unpacking' in line] assert 'parent' in downloaded[0], 'First download should ' \ 'be "parent" but was "%s"' % downloaded[0] assert 'child' in downloaded[1], 'Second download should ' \ 'be "child" but was "%s"' % downloaded[1] assert 'simple' in downloaded[2], 'Third download should ' \ 'be "simple" but was "%s"' % downloaded[2]
def test_download_should_skip_existing_files(): """ It should not download files already existing in the scratch dir """ env = reset_env() write_file('test-req.txt', textwrap.dedent(""" INITools==0.1 """)) result = run_pip('install', '-r', env.scratch_path / 'test-req.txt', '-d', '.', expect_error=True) assert Path('scratch') / 'INITools-0.1.tar.gz' in result.files_created assert env.site_packages / 'initools' not in result.files_created # adding second package to test-req.txt write_file( 'test-req.txt', textwrap.dedent(""" INITools==0.1 python-openid==2.2.5 """)) # only the second package should be downloaded result = run_pip('install', '-r', env.scratch_path / 'test-req.txt', '-d', '.', expect_error=True) openid_tarball_prefix = str(Path('scratch') / 'python-openid-') assert any( path.startswith(openid_tarball_prefix) for path in result.files_created) assert Path('scratch') / 'INITools-0.1.tar.gz' not in result.files_created assert env.site_packages / 'initools' not in result.files_created assert env.site_packages / 'openid' not in result.files_created
def _test_env_vars_override_config_file(config_file): environ = clear_environ(os.environ.copy()) environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it reset_env(environ) # It's important that we test this particular config value ('no-index') # because their is/was a bug which only shows up in cases in which # 'config-item' and 'config_item' hash to the same value modulo the size # of the config dictionary. write_file( config_file, textwrap.dedent("""\ [global] no-index = 1 """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "DistributionNotFound: No distributions at all found for INITools" in result.stdout environ['PIP_NO_INDEX'] = '0' reset_env(environ) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Successfully installed INITools" in result.stdout
def test_upgrade_from_reqs_file(): """ Upgrade from a requirements file. """ env = reset_env() write_file('test-req.txt', textwrap.dedent("""\ PyLogo<0.4 # and something else to test out: INITools==0.3 """)) install_result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt') write_file('test-req.txt', textwrap.dedent("""\ PyLogo # and something else to test out: INITools """)) run_pip('install', '--upgrade', '-r', env.scratch_path/ 'test-req.txt') uninstall_result = run_pip('uninstall', '-r', env.scratch_path/ 'test-req.txt', '-y') assert_all_changes(install_result, uninstall_result, [env.venv/'build', 'cache', env.scratch/'test-req.txt'])
def test_cleanup_after_create_bundle(): """ Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/. """ env = reset_env() # Install an editable to create a src/ dir. args = ['install'] args.extend([ '-e', '%s#egg=pip-test-package' % local_checkout('git+http://github.com/pypa/pip-test-package.git') ]) run_pip(*args) build = env.venv_path / "build" src = env.venv_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(tests_data, 'packages') pkg_lines = textwrap.dedent( '''\ -e %s -e %s#egg=initools-dev pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) write_file('bundle-req.txt', pkg_lines) run_pip('bundle', '-r', 'bundle-req.txt', 'test.pybundle') build_bundle = env.scratch_path / "build-bundle" src_bundle = env.scratch_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 env.assert_no_temp() # Make sure previously created src/ from editable still exists assert exists(src), "expected src dir doesn't exist: %s" % src
def test_freeze_with_requirement_option(): """ Test that new requirements are created correctly with --requirement hints """ reset_env() ignores = textwrap.dedent("""\ # Unchanged requirements below this line -r ignore.txt --requirement ignore.txt -Z ignore --always-unzip ignore -f http://ignore -i http://ignore --extra-index-url http://ignore --find-links http://ignore --index-url http://ignore """) write_file( 'hint.txt', textwrap.dedent("""\ INITools==0.1 NoExist==4.2 """) + ignores) result = run_pip('install', 'initools==0.2') result = pip_install_local('simple') result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True) expected = textwrap.dedent( """\ Script result: pip freeze --requirement hint.txt -- stderr: -------------------- Requirement file contains NoExist==4.2, but that package is not installed -- stdout: -------------------- INITools==0.2 """ ) + ignores + "## The following requirements were added by pip --freeze:..." _check_output(result, expected)
def _test_config_file_override_stack(config_file): environ = clear_environ(os.environ.copy()) environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it reset_env(environ) write_file(config_file, textwrap.dedent("""\ [global] index-url = http://download.zope.org/ppix """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Getting page http://download.zope.org/ppix/INITools" in result.stdout reset_env(environ) write_file(config_file, textwrap.dedent("""\ [global] index-url = http://download.zope.org/ppix [install] index-url = http://pypi.appspot.com/ """)) result = run_pip('install', '-vvv', 'INITools', expect_error=True) assert "Getting page http://pypi.appspot.com/INITools" in result.stdout result = run_pip('install', '-vvv', '--index-url', 'http://pypi.python.org/simple', 'INITools', expect_error=True) assert "Getting page http://download.zope.org/ppix/INITools" not in result.stdout assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout assert "Getting page http://pypi.python.org/simple/INITools" in result.stdout
def test_create_bundle(): """ Test making a bundle. We'll grab one package from the filesystem (the FSPkg dummy package), one from vcs (initools) and one from an index (pip itself). """ env = reset_env() fspkg = path_to_url2(Path(tests_data)/'packages'/'FSPkg') run_pip('install', '-e', fspkg) pkg_lines = textwrap.dedent('''\ -e %s -e %s#egg=initools-dev pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))) write_file('bundle-req.txt', pkg_lines) # Create a bundle in env.scratch_path/ test.pybundle result = run_pip('bundle', '-r', env.scratch_path/ 'bundle-req.txt', env.scratch_path/ 'test.pybundle') bundle = result.files_after.get(join('scratch', 'test.pybundle'), None) assert bundle is not None files = zipfile.ZipFile(bundle.full).namelist() assert 'src/FSPkg/' in files assert 'src/initools/' in files assert 'build/pip/' in files
def test_freeze_basic(): """ Some tests of freeze, first we have to install some stuff. Note that the test is a little crude at the end because Python 2.5+ adds egg info to the standard library, so stuff like wsgiref will show up in the freezing. (Probably that should be accounted for in pip, but currently it is not). """ env = reset_env() write_file('initools-req.txt', textwrap.dedent("""\ simple==2.0 # and something else to test out: simple2<=3.0 """)) result = pip_install_local('-r', env.scratch_path/'initools-req.txt') result = run_pip('freeze', expect_stderr=True) expected = textwrap.dedent("""\ Script result: pip freeze -- stdout: -------------------- ...simple==2.0 simple2==3.0... <BLANKLINE>""") _check_output(result, expected)
def _create_test_package_with_submodule(env): mkdir('version_pkg') version_pkg_path = env.scratch_path / 'version_pkg' mkdir(version_pkg_path / 'testpkg') pkg_path = version_pkg_path / 'testpkg' write_file('__init__.py', '# hello there', pkg_path) write_file( 'version_pkg.py', textwrap.dedent('''\ def main(): print('0.1') '''), pkg_path) write_file( 'setup.py', textwrap.dedent('''\ from setuptools import setup, find_packages setup(name='version_pkg', version='0.1', packages=find_packages(), ) '''), version_pkg_path) env.run('git', 'init', cwd=version_pkg_path, expect_error=True) env.run('git', 'add', '.', cwd=version_pkg_path, expect_error=True) env.run('git', 'commit', '-q', '--author', 'Pip <*****@*****.**>', '-am', 'initial version', cwd=version_pkg_path, expect_error=True) submodule_path = _create_test_package_submodule(env) env.run('git', 'submodule', 'add', submodule_path, 'testpkg/static', cwd=version_pkg_path, expect_error=True) env.run('git', 'commit', '-q', '--author', 'Pip <*****@*****.**>', '-am', 'initial version w submodule', cwd=version_pkg_path, expect_error=True) return version_pkg_path, submodule_path
def _create_test_package_with_submodule(env): mkdir('version_pkg') version_pkg_path = env.scratch_path/'version_pkg' mkdir(version_pkg_path/'testpkg') pkg_path = version_pkg_path/'testpkg' write_file('__init__.py', '# hello there', pkg_path) write_file('version_pkg.py', textwrap.dedent('''\ def main(): print('0.1') '''), pkg_path) write_file('setup.py', textwrap.dedent('''\ from setuptools import setup, find_packages setup(name='version_pkg', version='0.1', packages=find_packages(), ) '''), version_pkg_path) env.run('git', 'init', cwd=version_pkg_path, expect_error=True) env.run('git', 'add', '.', cwd=version_pkg_path, expect_error=True) env.run('git', 'commit', '-q', '--author', 'Pip <*****@*****.**>', '-am', 'initial version', cwd=version_pkg_path, expect_error=True) submodule_path = _create_test_package_submodule(env) env.run('git', 'submodule', 'add', submodule_path, 'testpkg/static', cwd=version_pkg_path, expect_error=True) env.run('git', 'commit', '-q', '--author', 'Pip <*****@*****.**>', '-am', 'initial version w submodule', cwd=version_pkg_path, expect_error=True) return version_pkg_path, submodule_path