diff --git a/tests/git_submodule_helpers.py b/tests/git_submodule_helpers.py new file mode 100644 index 0000000000000000000000000000000000000000..ad571207432053396be04e78a919c10a9fb4b0c2 --- /dev/null +++ b/tests/git_submodule_helpers.py @@ -0,0 +1,62 @@ +import textwrap +from tests.test_pip import (mkdir, write_file,) + +def _create_test_package_submodule(env): + mkdir('version_pkg_submodule') + submodule_path = env.scratch_path/'version_pkg_submodule' + env.run('touch', 'testfile', cwd=submodule_path) + env.run('git', 'init', cwd=submodule_path) + env.run('git', 'add', '.', cwd=submodule_path) + env.run('git', 'commit', '-q', + '--author', 'Pip ', + '-am', 'initial version / submodule', cwd=submodule_path) + return submodule_path + +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 _pull_in_submodule_changes_to_module(env, module_path): + env.run(*('git submodule foreach git pull -q origin master'.split(' ')), cwd=module_path) # this only exists in git > 1.7.3 + env.run('git', 'commit', '-q', + '--author', 'Pip ', + '-am', 'submodule change', cwd=module_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) + env.run('git', 'add', '.', cwd=version_pkg_path) + env.run('git', 'commit', '-q', + '--author', 'Pip ', + '-am', 'initial version', cwd=version_pkg_path) + + + submodule_path = _create_test_package_submodule(env) + + env.run('git', 'submodule', 'add', submodule_path, 'testpkg/static', cwd=version_pkg_path) + env.run('git', 'commit', '-q', + '--author', 'Pip ', + '-am', 'initial version w submodule', cwd=version_pkg_path) + + + return version_pkg_path, submodule_path diff --git a/tests/test_vcs_git.py b/tests/test_vcs_git.py index 0b3abab2e1331de3de7e2d51ade45042e2b6d794..227f6573705125ce8914346781a64aee8ec6482c 100644 --- a/tests/test_vcs_git.py +++ b/tests/test_vcs_git.py @@ -1,7 +1,8 @@ from mock import patch from pip.vcs.git import Git from tests.test_pip import (reset_env, run_pip, - _create_test_package) + _create_test_package,) +from tests.git_submodule_helpers import _create_test_package_submodule, _change_test_package_submodule, _pull_in_submodule_changes_to_module, _create_test_package_with_submodule def test_get_tag_revs_should_return_tag_name_and_commit_pair(): @@ -75,3 +76,26 @@ def test_check_rev_options_should_handle_ambiguous_commit(branches_revs_mock, result = git.check_rev_options('0.1', '.', []) assert result == ['123456'], result + + + + + + +def test_check_submodule_addition(): + """ + Test if submodules will be pulled in on install, and updated on upgrade + """ + env = reset_env() + module_path, submodule_path = _create_test_package_with_submodule(env) + + install_result = run_pip('install', '-e', 'git+'+module_path+'#egg=version_pkg') + assert '.virtualenv/src/version-pkg/testpkg/static/testfile' in install_result.files_created + + _change_test_package_submodule(env, submodule_path) + _pull_in_submodule_changes_to_module(env, module_path) + + update_result = run_pip('install', '-e', 'git+'+module_path+'#egg=version_pkg', '--upgrade') + + assert env.venv/'src/version-pkg/testpkg/static/testfile2' in update_result.files_created +