mirror of https://github.com/pypa/pip
Eliminated all direct uses of diff_states, instead using a new
assert_all_changes, which DRY's things out substantially
This commit is contained in:
parent
9ad75fe6ba
commit
96962d5322
|
@ -1,7 +1,7 @@
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import textwrap
|
import textwrap
|
||||||
from test_pip import here, reset_env, run_pip, pyversion, diff_states, write_file
|
from test_pip import here, reset_env, run_pip, pyversion, write_file
|
||||||
from path import Path
|
from path import Path
|
||||||
|
|
||||||
def test_download_if_requested():
|
def test_download_if_requested():
|
||||||
|
|
|
@ -338,6 +338,22 @@ def diff_states(start, end, ignore=None):
|
||||||
updated[k] = end[k]
|
updated[k] = end[k]
|
||||||
return dict(deleted=deleted, created=created, updated=updated)
|
return dict(deleted=deleted, created=created, updated=updated)
|
||||||
|
|
||||||
|
def assert_all_changes( start_result, end_result, expected_changes ):
|
||||||
|
"""
|
||||||
|
Accepts two TestPipResult objects (possibly both the same object)
|
||||||
|
and a list of (relative) paths. Fails if anything changed that
|
||||||
|
isn't listed in the expected_changes. Note: listing a directory
|
||||||
|
means anything below that directory can be expected to have changed.
|
||||||
|
"""
|
||||||
|
diff = diff_states( start_result.files_before, end_result.files_after, ignore=expected_changes )
|
||||||
|
if diff.values() != [{},{},{}]:
|
||||||
|
import pprint
|
||||||
|
raise TestFailure, 'Unexpected changes:\n' + '\n'.join(
|
||||||
|
[k + ': ' + ', '.join(v.keys()) for k,v in diff.items()])
|
||||||
|
|
||||||
|
# Don't throw away this potentially useful information
|
||||||
|
return diff
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.stderr.write("Run pip's tests using nosetests. Requires virtualenv, ScriptTest, and nose.\n")
|
sys.stderr.write("Run pip's tests using nosetests. Requires virtualenv, ScriptTest, and nose.\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import textwrap, sys
|
import textwrap, sys
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from test_pip import here, reset_env, run_pip, get_env, diff_states, write_file
|
from test_pip import here, reset_env, run_pip, get_env, assert_all_changes, write_file
|
||||||
from path import Path
|
from path import Path
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
|
@ -15,27 +15,24 @@ def test_simple_uninstall():
|
||||||
result = run_pip('install', 'INITools==0.2', expect_error=True)
|
result = run_pip('install', 'INITools==0.2', expect_error=True)
|
||||||
assert join(env.site_packages, 'initools') in result.files_created, sorted(result.files_created.keys())
|
assert join(env.site_packages, 'initools') in result.files_created, sorted(result.files_created.keys())
|
||||||
result2 = run_pip('uninstall', 'INITools', '-y', expect_error=True)
|
result2 = run_pip('uninstall', 'INITools', '-y', expect_error=True)
|
||||||
assert diff_states(result.files_before, result2.files_after, ignore=[env.venv/'build', 'cache']).values() == [{}, {}, {}]
|
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
|
||||||
|
|
||||||
def test_uninstall_with_scripts():
|
def test_uninstall_with_scripts():
|
||||||
"""
|
"""
|
||||||
Uninstall an easy_installed package with scripts.
|
Uninstall an easy_installed package with scripts.
|
||||||
|
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
Uninstall an easy_installed package with scripts.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
env = reset_env()
|
env = reset_env()
|
||||||
result = env.run('easy_install', 'PyLogo')
|
result = env.run('easy_install', 'PyLogo')
|
||||||
easy_install_pth = env.site_packages/ 'easy-install.pth'
|
easy_install_pth = env.site_packages/ 'easy-install.pth'
|
||||||
easy_install_pth_bytes = result.files_updated[easy_install_pth].bytes
|
pylogo = 'pylogo' if sys.platform == 'win32' else 'PyLogo'
|
||||||
assert('pylogo' in easy_install_pth_bytes.lower()), easy_install_pth_bytes
|
assert(pylogo in result.files_updated[easy_install_pth].bytes)
|
||||||
result2 = run_pip('uninstall', 'pylogo', '-y', expect_error=True)
|
result2 = run_pip('uninstall', 'pylogo', '-y', expect_error=True)
|
||||||
diff = diff_states(result.files_before, result2.files_after, ignore=[env.venv/'build', 'cache', easy_install_pth])
|
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
|
||||||
easy_install_pth_bytes2 = result.files_updated[easy_install_pth].bytes
|
|
||||||
if sys.platform == 'win32':
|
|
||||||
easy_install_pth_bytes2.replace('\r\n','\n')
|
|
||||||
assert easy_install_pth_bytes == easy_install_pth_bytes2, pprint.pformat(easy_install_pth_bytes, easy_install_pth_bytes2)
|
|
||||||
### This assertion is currently (correctly) failing on Windows,
|
|
||||||
### indicating that env\Scripts\pylogo.exe.manifest isn't getting cleaned up
|
|
||||||
assert diff.values() == [{}, {}, {}], pprint.pformat(diff)
|
|
||||||
|
|
||||||
def test_uninstall_namespace_package():
|
def test_uninstall_namespace_package():
|
||||||
"""
|
"""
|
||||||
|
@ -59,7 +56,7 @@ def test_uninstall_console_scripts():
|
||||||
result = run_pip('install', 'virtualenv', expect_error=True)
|
result = run_pip('install', 'virtualenv', expect_error=True)
|
||||||
assert env.bin/'virtualenv'+env.exe in result.files_created, sorted(result.files_created.keys())
|
assert env.bin/'virtualenv'+env.exe in result.files_created, sorted(result.files_created.keys())
|
||||||
result2 = run_pip('uninstall', 'virtualenv', '-y', expect_error=True)
|
result2 = run_pip('uninstall', 'virtualenv', '-y', expect_error=True)
|
||||||
assert diff_states(result.files_before, result2.files_after, ignore=[env.venv/'build', 'cache']).values() == [{}, {}, {}]
|
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
|
||||||
|
|
||||||
def test_uninstall_easy_installed_console_scripts():
|
def test_uninstall_easy_installed_console_scripts():
|
||||||
"""
|
"""
|
||||||
|
@ -70,7 +67,7 @@ def test_uninstall_easy_installed_console_scripts():
|
||||||
result = env.run('easy_install', 'virtualenv')
|
result = env.run('easy_install', 'virtualenv')
|
||||||
assert env.bin/'virtualenv'+env.exe in result.files_created, sorted(result.files_created.keys())
|
assert env.bin/'virtualenv'+env.exe in result.files_created, sorted(result.files_created.keys())
|
||||||
result2 = run_pip('uninstall', 'virtualenv', '-y')
|
result2 = run_pip('uninstall', 'virtualenv', '-y')
|
||||||
assert diff_states(result.files_before, result2.files_after, ignore=[env.venv/'build', 'cache']).values() == [{}, {}, {}]
|
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
|
||||||
|
|
||||||
def test_uninstall_editable_from_svn():
|
def test_uninstall_editable_from_svn():
|
||||||
"""
|
"""
|
||||||
|
@ -82,7 +79,7 @@ def test_uninstall_editable_from_svn():
|
||||||
result.assert_installed('INITools')
|
result.assert_installed('INITools')
|
||||||
result2 = run_pip('uninstall', '-y', 'initools')
|
result2 = run_pip('uninstall', '-y', 'initools')
|
||||||
assert (env.venv/'src'/'initools' in result2.files_after), 'oh noes, pip deleted my sources!'
|
assert (env.venv/'src'/'initools' in result2.files_after), 'oh noes, pip deleted my sources!'
|
||||||
assert diff_states(result.files_before, result2.files_after, ignore=[env.venv/'src', env.venv/'build']).values() == [{}, {}, {}], result
|
assert_all_changes(result, result2, [env.venv/'src', env.venv/'build'])
|
||||||
|
|
||||||
|
|
||||||
def test_uninstall_editable_with_source_outside_venv():
|
def test_uninstall_editable_with_source_outside_venv():
|
||||||
|
@ -96,8 +93,7 @@ def test_uninstall_editable_with_source_outside_venv():
|
||||||
result2 = run_pip('install', '-e', tmpdir)
|
result2 = run_pip('install', '-e', tmpdir)
|
||||||
assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), result2.files_created.keys()
|
assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), result2.files_created.keys()
|
||||||
result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True)
|
result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True)
|
||||||
assert diff_states(result.files_before, result3.files_after, ignore=[env.venv/'build']).values() == [{}, {}, {}], result
|
assert_all_changes(result, result3, [env.venv/'build'])
|
||||||
|
|
||||||
|
|
||||||
def test_uninstall_from_reqs_file():
|
def test_uninstall_from_reqs_file():
|
||||||
"""
|
"""
|
||||||
|
@ -122,4 +118,5 @@ def test_uninstall_from_reqs_file():
|
||||||
PyLogo<0.4
|
PyLogo<0.4
|
||||||
"""))
|
"""))
|
||||||
result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
|
result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
|
||||||
assert diff_states(result.files_before, result2.files_after, ignore=[env.venv/'build', env.venv/'src', Path('scratch')/'test-req.txt']).values() == [{}, {}, {}], result
|
assert_all_changes(
|
||||||
|
result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import textwrap
|
import textwrap
|
||||||
from test_pip import here, reset_env, run_pip, get_env, diff_states, write_file
|
from test_pip import here, reset_env, run_pip, get_env, assert_all_changes, write_file
|
||||||
|
|
||||||
def test_no_upgrade_unless_requested():
|
def test_no_upgrade_unless_requested():
|
||||||
"""
|
"""
|
||||||
|
@ -44,7 +44,7 @@ def test_uninstall_before_upgrade():
|
||||||
result2 = run_pip('install', 'INITools==0.3', expect_error=True)
|
result2 = run_pip('install', 'INITools==0.3', expect_error=True)
|
||||||
assert result2.files_created, 'upgrade to INITools 0.3 failed'
|
assert result2.files_created, 'upgrade to INITools 0.3 failed'
|
||||||
result3 = run_pip('uninstall', 'initools', '-y', expect_error=True)
|
result3 = run_pip('uninstall', 'initools', '-y', expect_error=True)
|
||||||
assert diff_states(result.files_before, result3.files_after, ignore=['env/build', 'cache']).values() == [{}, {}, {}]
|
assert_all_changes(result, result3, ['env/build', 'cache'])
|
||||||
|
|
||||||
def test_upgrade_from_reqs_file():
|
def test_upgrade_from_reqs_file():
|
||||||
"""
|
"""
|
||||||
|
@ -65,8 +65,7 @@ def test_upgrade_from_reqs_file():
|
||||||
"""))
|
"""))
|
||||||
result2 = run_pip('install', '--upgrade', '-r', env.scratch_path/ 'test-req.txt')
|
result2 = run_pip('install', '--upgrade', '-r', env.scratch_path/ 'test-req.txt')
|
||||||
result3 = run_pip('uninstall', '-r', env.scratch_path/ 'test-req.txt', '-y')
|
result3 = run_pip('uninstall', '-r', env.scratch_path/ 'test-req.txt', '-y')
|
||||||
res = diff_states(result.files_before, result3.files_after, ignore=['env/build', 'cache', 'scratch/test-req.txt']).values()
|
assert_all_changes(result, result3, ['env/build', 'cache', 'scratch/test-req.txt'])
|
||||||
assert res == [{}, {}, {}], res
|
|
||||||
|
|
||||||
def test_uninstall_rollback():
|
def test_uninstall_rollback():
|
||||||
"""
|
"""
|
||||||
|
@ -82,4 +81,4 @@ def test_uninstall_rollback():
|
||||||
assert result2.returncode == 1, str(result2)
|
assert result2.returncode == 1, str(result2)
|
||||||
env.run( 'python', '-c', "import broken; print broken.VERSION").stdout
|
env.run( 'python', '-c', "import broken; print broken.VERSION").stdout
|
||||||
'0.1\n'
|
'0.1\n'
|
||||||
assert diff_states(result.files_after, result2.files_after, ignore=[env.venv/'build', 'pip-log.txt']).values() == [{}, {}, {}]
|
assert_all_changes(result, result2, [env.venv/'build', 'pip-log.txt'])
|
||||||
|
|
Loading…
Reference in New Issue