Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipx: add new states #8809

Merged
merged 12 commits into from
Sep 6, 2024
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
russoz committed Aug 27, 2024
commit a00c61fa10b84eb05b4be78820e7a2622cf75a72
91 changes: 91 additions & 0 deletions tests/integration/targets/pipx/files/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"pipx_spec_version": "0.1",
"venvs": {
"black": {
"metadata": {
"injected_packages": {},
"main_package": {
"app_paths": [
{
"__Path__": "/home/az/.local/pipx/venvs/black/bin/black",
"__type__": "Path"
},
{
"__Path__": "/home/az/.local/pipx/venvs/black/bin/blackd",
"__type__": "Path"
}
],
"app_paths_of_dependencies": {},
"apps": [
"black",
"blackd"
],
"apps_of_dependencies": [],
"include_apps": true,
"include_dependencies": false,
"man_pages": [],
"man_pages_of_dependencies": [],
"man_paths": [],
"man_paths_of_dependencies": {},
"package": "black",
"package_or_url": "black",
"package_version": "24.8.0",
"pinned": false,
"pip_args": [],
"suffix": ""
},
"pipx_metadata_version": "0.5",
"python_version": "Python 3.11.9",
"source_interpreter": {
"__Path__": "/home/az/.pyenv/versions/3.11.9/bin/python3.11",
"__type__": "Path"
},
"venv_args": []
}
},
"pycowsay": {
"metadata": {
"injected_packages": {},
"main_package": {
"app_paths": [
{
"__Path__": "/home/az/.local/pipx/venvs/pycowsay/bin/pycowsay",
"__type__": "Path"
}
],
"app_paths_of_dependencies": {},
"apps": [
"pycowsay"
],
"apps_of_dependencies": [],
"include_apps": true,
"include_dependencies": false,
"man_pages": [
"man6/pycowsay.6"
],
"man_pages_of_dependencies": [],
"man_paths": [
{
"__Path__": "/home/az/.local/pipx/venvs/pycowsay/share/man/man6/pycowsay.6",
"__type__": "Path"
}
],
"man_paths_of_dependencies": {},
"package": "pycowsay",
"package_or_url": "pycowsay",
"package_version": "0.0.0.2",
"pinned": false,
"pip_args": [],
"suffix": ""
},
"pipx_metadata_version": "0.5",
"python_version": "Python 3.11.9",
"source_interpreter": {
"__Path__": "/home/az/.pyenv/versions/3.11.9/bin/python3.11",
"__type__": "Path"
},
"venv_args": []
}
},
}
}
6 changes: 6 additions & 0 deletions tests/integration/targets/pipx/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,9 @@
block:
- name: Include testcase for PR 8793 --global
ansible.builtin.include_tasks: testcase-8793-global.yml

- name: Include testcase for PR 8809 install-all
ansible.builtin.include_tasks: testcase-8809-install-all.yml

- name: Include testcase for PR 8809 pin
ansible.builtin.include_tasks: testcase-8809-pin.yml
59 changes: 59 additions & 0 deletions tests/integration/targets/pipx/tasks/testcase-8809-installall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Set up environment
environment:
PATH: /usr/local/bin:{{ ansible_env.PATH }}
block:
- name: Uninstall pycowsay and black
community.general.pipx:
state: uninstall
name: "{{ item }}"
loop:
- black
- pycowsay

- name: Uninstall pycowsay and black (again)
community.general.pipx:
state: uninstall
name: "{{ item }}"
loop:
- black
- pycowsay
register: uninstall_all_1

- name: Use install-all
community.general.pipx:
state: install-all
spec_metadata: spec.json
register: install_all

- name: Run pycowsay (should succeed)
ansible.builtin.command: pycowsay Moooooooo!
changed_when: false
register: what_the_cow_said

- name: Which cow?
ansible.builtin.command: which pycowsay
changed_when: false
register: which_cow

- name: Uninstall pycowsay and black (again)
community.general.pipx:
state: uninstall
name: "{{ item }}"
loop:
- black
- pycowsay
register: uninstall_all_2

- name: Assert uninstall-all
ansible.builtin.assert:
that:
- uninstall_all_1 is not changed
- install_all is changed
- "'Moooooooo!' in what_the_cow_said.stdout"
- "'/usr/local/bin/pycowsay' in which_cow.stdout"
- uninstall_all_2 is changed
69 changes: 69 additions & 0 deletions tests/integration/targets/pipx/tasks/testcase-8809-pin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Set up environment
environment:
PATH: /usr/local/bin:{{ ansible_env.PATH }}
block:
- name: Uninstall pycowsay and black
community.general.pipx:
state: uninstall
name: pycowsay

# latest is 0.0.0.2
- name: Install pycowsay 0.0.0.1
community.general.pipx:
state: install
name: pycowsay
source: pycowsay==0.0.0.1

- name: Pin cowsay
community.general.pipx:
state: pin
name: pycowsay
register: pin_cow

- name: Upgrade pycowsay
community.general.pipx:
state: upgrade
name: pycowsay

- name: Get pycowsay version
community.general.pipx_info:
name: pycowsay
register: cow_info_1

- name: Unpin cowsay
community.general.pipx:
state: unpin
name: pycowsay
register: unpin_cow

- name: Upgrade pycowsay
community.general.pipx:
state: upgrade
name: pycowsay

- name: Get pycowsay version
community.general.pipx_info:
name: pycowsay
register: cow_info_2

- name: Uninstall pycowsay and black (again)
community.general.pipx:
state: uninstall
name: "{{ item }}"
loop:
- black
- pycowsay
register: uninstall_all_2

- name: Assert uninstall-all
ansible.builtin.assert:
that:
- pin_cow is changed
- cow_info_1 == "0.0.0.1"
- unpin_cow is changed
- cow_info_2 != "0.0.0.1"
21 changes: 15 additions & 6 deletions tests/integration/targets/pipx/tasks/testcase-injectpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- name: ensure application pylint is uninstalled
- name: Ensure application pylint is uninstalled
community.general.pipx:
name: pylint
state: absent

- name: install application pylint
- name: Install application pylint
community.general.pipx:
name: pylint
register: install_pylint

- name: inject packages
- name: Inject packages
community.general.pipx:
state: inject
name: pylint
inject_packages:
- licenses
register: inject_pkgs_pylint

- name: inject packages with apps
- name: Inject packages with apps
community.general.pipx:
state: inject
name: pylint
Expand All @@ -30,13 +30,21 @@
install_apps: true
register: inject_pkgs_apps_pylint

- name: cleanup pylint
- name: Uninject package
community.general.pipx:
state: uninject
name: pylint
inject_packages:
- black
register: uninject_b

- name: Cleanup pylint
community.general.pipx:
state: absent
name: pylint
register: uninstall_pylint

- name: check assertions inject_packages
- name: Check assertions inject_packages
assert:
that:
- install_pylint is changed
Expand All @@ -47,3 +55,4 @@
- '"pylint" in inject_pkgs_apps_pylint.application'
- '"black" in inject_pkgs_apps_pylint.application["pylint"]["injected"]'
- uninstall_pylint is changed
- uninject_b is changed
Loading