Allow version specifiers for pip install (#41792)

Allow version specifiers for pip install.
This commit is contained in:
Zhikang Zhang 2018-08-17 11:46:53 -04:00 committed by GitHub
commit 501503f4cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 335 additions and 28 deletions

View file

@ -315,3 +315,162 @@
assert:
that:
- pip_install_empty_version_string is successful
# test version specifiers
- name: make sure no test_package installed now
pip:
name: "{{ pip_test_packages }}"
state: absent
- name: install package with version specifiers
pip:
name: "{{ pip_test_package }}"
version: "<100,!=1.0,>0.0.0"
register: version
- name: assert package installed correctly
assert:
that: "version.changed"
- name: reinstall package
pip:
name: "{{ pip_test_package }}"
version: "<100,!=1.0,>0.0.0"
register: version2
- name: assert no changes ocurred
assert:
that: "not version2.changed"
- name: test the check_mod
pip:
name: "{{ pip_test_package }}"
version: "<100,!=1.0,>0.0.0"
check_mode: yes
register: version3
- name: assert no changes
assert:
that: "not version3.changed"
- name: test the check_mod with unsatisfied version
pip:
name: "{{ pip_test_package }}"
version: ">100.0.0"
check_mode: yes
register: version4
- name: assert changed
assert:
that: "version4.changed"
- name: uninstall test packages for next test
pip:
name: "{{ pip_test_packages }}"
state: absent
- name: test invalid combination of arguments
pip:
name: "{{ pip_test_pkg_ver }}"
version: "1.11.1"
ignore_errors: yes
register: version5
- name: assert the invalid combination should fail
assert:
that: "version5 is failed"
- name: another invalid combination of arguments
pip:
name: "{{ pip_test_pkg_ver[0] }}"
version: "<100.0.0"
ignore_errors: yes
register: version6
- name: assert invalid combination should fail
assert:
that: "version6 is failed"
- name: try to install invalid package
pip:
name: "{{ pip_test_pkg_ver_unsatisfied }}"
ignore_errors: yes
register: version7
- name: assert install should fail
assert:
that: "version7 is failed"
- name: test install multi-packages with version specifiers
pip:
name: "{{ pip_test_pkg_ver }}"
register: version8
- name: assert packages installed correctly
assert:
that: "version8.changed"
- name: test install multi-packages with check_mode
pip:
name: "{{ pip_test_pkg_ver }}"
check_mode: yes
register: version9
- name: assert no change
assert:
that: "not version9.changed"
- name: test install unsatisfied multi-packages with check_mode
pip:
name: "{{ pip_test_pkg_ver_unsatisfied }}"
check_mode: yes
register: version10
- name: assert changes needed
assert:
that: "version10.changed"
- name: uninstall packages for next test
pip:
name: "{{ pip_test_packages }}"
state: absent
- name: test install multi package provided by one single string
pip:
name: "{{pip_test_pkg_ver[0]}},{{pip_test_pkg_ver[1]}}"
register: version11
- name: assert the install ran correctly
assert:
that: "version11.changed"
- name: test install multi package provided by one single string with check_mode
pip:
name: "{{pip_test_pkg_ver[0]}},{{pip_test_pkg_ver[1]}}"
check_mode: yes
register: version12
- name: assert no changes needed
assert:
that: "not version12.changed"
- name: test module can parse the combination of multi-packages one line and git url
pip:
name:
- git+https://github.com/dvarrazzo/pyiso8601#egg=pyiso8601
- "{{pip_test_pkg_ver[0]}},{{pip_test_pkg_ver[1]}}"
- name: test the invalid package name
pip:
name: djan=+-~!@#$go>1.11.1,<1.11.3
ignore_errors: yes
register: version13
- name: the invalid package should make module failed
assert:
that: "version13 is failed"
- name: clean up
pip:
name: "{{ pip_test_packages }}"
state: absent

View file

@ -2,6 +2,12 @@ pip_test_package: sampleproject
pip_test_packages:
- sampleproject
- decorator
pip_test_pkg_ver:
- sampleproject<=100, !=9.0.0,>=0.0.1
- decorator<100 ,!=9,>=0.0.1
pip_test_pkg_ver_unsatisfied:
- sampleproject>= 999.0.0
- decorator >999.0
pip_test_modules:
- sample
- decorator

View file

@ -22,3 +22,14 @@ def test_failure_when_pip_absent(mocker, capfd):
results = json.loads(out)
assert results['failed']
assert 'pip needs to be installed' in results['msg']
@pytest.mark.parametrize('patch_ansible_module, test_input, expected', [
[None, ['django>1.11.1', '<1.11.2', 'ipaddress', 'simpleproject<2.0.0', '>1.1.0'],
['django>1.11.1,<1.11.2', 'ipaddress', 'simpleproject<2.0.0,>1.1.0']],
[None, ['django>1.11.1,<1.11.2,ipaddress', 'simpleproject<2.0.0,>1.1.0'],
['django>1.11.1,<1.11.2', 'ipaddress', 'simpleproject<2.0.0,>1.1.0']],
[None, ['django>1.11.1', '<1.11.2', 'ipaddress,simpleproject<2.0.0,>1.1.0'],
['django>1.11.1,<1.11.2', 'ipaddress', 'simpleproject<2.0.0,>1.1.0']]])
def test_recover_package_name(test_input, expected):
assert pip._recover_package_name(test_input) == expected