Skip to content

Commit

Permalink
Adds tests for proper recursive upgrade behavior. refs pypa#304
Browse files Browse the repository at this point in the history
  • Loading branch information
ejucovy authored and fdintino committed Jul 18, 2012
1 parent 2f66454 commit 7d86207
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/packages/FSPkgUsesInitools/fspkg/__init__.py
@@ -0,0 +1 @@
#
25 changes: 25 additions & 0 deletions tests/packages/FSPkgUsesInitools/setup.py
@@ -0,0 +1,25 @@
from setuptools import setup, find_packages

version = '0.1'

setup(name='FSPkgUsesInitools',
version=version,
description="File system test package",
long_description="""\
File system test package""",
classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords='pip tests',
author='pip',
author_email='pip@openplans.org',
url='http://pip.openplans.org',
license='',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
install_requires=[
"INItools",
],
entry_points="""
# -*- Entry points: -*-
""",
)
1 change: 1 addition & 0 deletions tests/packages/FSPkgUsesNewishInitools/fspkg/__init__.py
@@ -0,0 +1 @@
#
25 changes: 25 additions & 0 deletions tests/packages/FSPkgUsesNewishInitools/setup.py
@@ -0,0 +1,25 @@
from setuptools import setup, find_packages

version = '0.1'

setup(name='FSPkgUsesNewishInitools',
version=version,
description="File system test package",
long_description="""\
File system test package""",
classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords='pip tests',
author='pip',
author_email='pip@openplans.org',
url='http://pip.openplans.org',
license='',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
install_requires=[
"INItools>=0.3",
],
entry_points="""
# -*- Entry points: -*-
""",
)
6 changes: 6 additions & 0 deletions tests/test_pip.py
Expand Up @@ -379,6 +379,12 @@ def run(self, *args, **kw):
assert not isinstance(cwd, Path)
return TestPipResult(super(TestPipEnvironment, self).run(cwd=cwd, *args, **kw), verbose=self.verbose)

def get_pkg_version(self, pkg_name):
result = self.run('python', '-c',
"from pkg_resources import get_distribution; "
"print(get_distribution('%s').version)" % pkg_name)
return result.stdout.strip()

def __del__(self):
rmtree(str(self.root_path), ignore_errors=True)

Expand Down
83 changes: 82 additions & 1 deletion tests/test_upgrade.py
@@ -1,5 +1,6 @@
import textwrap
from os.path import join
from os.path import abspath, join
from pkg_resources import parse_version
from nose.tools import nottest
from tests.test_pip import (here, reset_env, run_pip, assert_all_changes,
write_file, pyversion, _create_test_package,
Expand Down Expand Up @@ -56,6 +57,86 @@ def test_upgrade_with_newest_already_installed():
assert 'already up-to-date' in result.stdout


def test_upgrade_without_unneeded_recursive_upgrades():
"""
When upgrading a single package, that package's own dependencies should not be
upgraded unnecessarily if the user doesn't explicitly ask for them to be upgraded.
"""
env = reset_env()
run_pip('install', 'INITools==0.2')

to_install = abspath(join(here, 'packages', 'FSPkgUsesInitools'))
run_pip('install', to_install)
run_pip('install', '--upgrade', to_install)
assert env.get_pkg_version('initools') == '0.2',\
('pip install --upgrade upgraded recursive dependency INITools '
'when it should not have')


def test_upgrade_with_needed_recursive_upgrades():
"""
When upgrading a single package A, that package's own dependencies should be
upgraded if the installed versions no longer satisfy A's requirements, even if
the user doesn't explicitly ask for them to be upgraded,
"""
env = reset_env()
to_install = abspath(join(here, 'packages', 'FSPkgUsesNewishInitools'))
run_pip('install', to_install)
run_pip('install', 'INITools==0.2')
run_pip('install', '--upgrade', to_install)
current_version = env.get_pkg_version('initools')
assert parse_version(current_version) >= parse_version('0.3'),\
('pip install --upgrade failed to upgrade recursive dependency '
'INITools when it should have')


def test_upgrade_with_unneeded_recursive_upgrades_explicitly_requested():
"""
When upgrading a single package A with --upgrade-recursive, all of A's
dependencies should be upgraded as well, even if the installed versions
already satisfy A's requirements.
"""
env = reset_env()
run_pip('install', 'INITools==0.2')

to_install = abspath(join(here, 'packages', 'FSPkgUsesInitools'))
run_pip('install', to_install)
run_pip('install', '--upgrade-recursive', to_install)
current_version = env.get_pkg_version('initools')
assert parse_version(current_version) > parse_version('0.2'),\
('pip install --upgrade failed to upgrade recursive dependency '
'INITools when it was asked to')


def test_upgrade_reqs_file_without_unneeded_recursive_upgrades():
"""
When running non-recursive --upgrade against a requirements file, every package
explicitly listed in the requirements file should be upgraded; but any recursive
dependencies should not be upgraded.
"""
env = reset_env()
run_pip('install', 'INITools==0.2')
run_pip('install', 'PyLogo==0.1')

to_install = abspath(join(here, 'packages', 'FSPkgUsesInitools'))
run_pip('install', to_install)

write_file('test-req.txt', textwrap.dedent("""\
%(FSPkgUsesInitools)s
PyLogo
""" % {'FSPkgUsesInitools': to_install}))

run_pip('install', '--upgrade', '-r', env.scratch_path/ 'test-req.txt')

pylogo_version = env.get_pkg_version('pylogo')
assert parse_version(pylogo_version) > parse_version('0.1'),\
('pip install --upgrade failed to upgrade explicit dependency '
'PyLogo when it should have')
assert env.get_pkg_version('initools') == '0.2',\
('pip install --upgrade upgraded recursive dependency INITools '
'when it should not have')


def test_upgrade_force_reinstall_newest():
"""
Force reinstallation of a package even if it is already at its newest
Expand Down

0 comments on commit 7d86207

Please sign in to comment.