Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maisim committed Aug 29, 2024
1 parent 7d9c9ec commit 4fbec13
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 52 deletions.
12 changes: 7 additions & 5 deletions pyinfra/operations/pipx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""

from pyinfra import host
from pyinfra.api import operation
from pyinfra.api import OperationError, operation
from pyinfra.facts.pipx import PipxEnvironment, PipxPackages
from pyinfra.facts.server import Path
from pyinfra.facts.pipx import PipxPackages, PipxEnvironment

from .util.packaging import ensure_packages

Expand All @@ -29,7 +29,7 @@ def packages(
+ extra_install_args: additional arguments to the pipx install command
Versions:
Package versions can be pinned like pipx: ``<pkg>==<version>``.
Package versions can be pinned like pip: ``<pkg>==<version>``.
**Example:**
Expand All @@ -56,6 +56,9 @@ def packages(
if packages:
current_packages = host.get_fact(PipxPackages, pipx=pipx)

if current_packages is None:
raise OperationError("Unable to get pipx packages")

# pipx support only one package name at a time
for package in packages:
yield from ensure_packages(
Expand All @@ -76,7 +79,6 @@ def upgrade_all(pipx="pipx"):
"""
Upgrade all pipx packages.
"""

yield f"{pipx} upgrade-all"


Expand All @@ -93,6 +95,6 @@ def ensure_path(pipx="pipx"):

# If the pipx bin dir is already in the user's PATH, we're done
if pipx_env["PIPX_BIN_DIR"] in path.split(":"):
return
host.noop("pipx bin dir is already in the PATH")
else:
yield f"{pipx} ensurepath"
22 changes: 22 additions & 0 deletions tests/facts/pipx.PipxEnvironment/environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"command": "pipx environment",
"requires_command": "pipx",
"output": [
"PIPX_HOME=/home/doodba/.local/pipx",
"PIPX_BIN_DIR=/home/doodba/.local/bin",
"PIPX_SHARED_LIBS=/home/doodba/.local/pipx/shared",
"PIPX_LOCAL_VENVS=/home/doodba/.local/pipx/venvs",
"PIPX_LOG_DIR=/home/doodba/.local/pipx/logs",
"PIPX_TRASH_DIR=/home/doodba/.local/pipx/.trash",
"PIPX_VENV_CACHEDIR=/home/doodba/.local/pipx/.cache"
],
"fact": {
"PIPX_HOME": "/home/doodba/.local/pipx",
"PIPX_BIN_DIR": "/home/doodba/.local/bin",
"PIPX_SHARED_LIBS": "/home/doodba/.local/pipx/shared",
"PIPX_LOCAL_VENVS": "/home/doodba/.local/pipx/venvs",
"PIPX_LOG_DIR": "/home/doodba/.local/pipx/logs",
"PIPX_TRASH_DIR": "/home/doodba/.local/pipx/.trash",
"PIPX_VENV_CACHEDIR": "/home/doodba/.local/pipx/.cache"
}
}
12 changes: 0 additions & 12 deletions tests/facts/pipx.PipxEnvironment/packages.json

This file was deleted.

22 changes: 6 additions & 16 deletions tests/facts/pipx.PipxPackages/packages.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
{
"command": "pipx environment",
"command": "pipx list --short",
"requires_command": "pipx",
"output": [
"PIPX_HOME=/home/doodba/.local/pipx",
"PIPX_BIN_DIR=/home/doodba/.local/bin",
"PIPX_SHARED_LIBS=/home/doodba/.local/pipx/shared",
"PIPX_LOCAL_VENVS=/home/doodba/.local/pipx/venvs",
"PIPX_LOG_DIR=/home/doodba/.local/pipx/logs",
"PIPX_TRASH_DIR=/home/doodba/.local/pipx/.trash",
"PIPX_VENV_CACHEDIR=/home/doodba/.local/pipx/.cache"
"copier 9.0.1",
"invoke 2.2.0"
],
"fact": {
"PIPX_HOME": "/home/doodba/.local/pipx",
"PIPX_BIN_DIR": "/home/doodba/.local/bin",
"PIPX_SHARED_LIBS": "/home/doodba/.local/pipx/shared",
"PIPX_LOCAL_VENVS": "/home/doodba/.local/pipx/venvs",
"PIPX_LOG_DIR": "/home/doodba/.local/pipx/logs",
"PIPX_TRASH_DIR": "/home/doodba/.local/pipx/.trash",
"PIPX_VENV_CACHEDIR": "/home/doodba/.local/pipx/.cache"
}
"copier": ["9.0.1"],
"invoke": ["2.2.0"]
}
}
2 changes: 1 addition & 1 deletion tests/operations/pipx.ensure_path/ensure_path.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"args": [["copier==9.0.1", "invoke"]],
"args": [],
"facts": {
"pipx.PipxEnvironment": {
"PIPX_HOME": "/home/doodba/.local/pipx",
Expand Down
6 changes: 3 additions & 3 deletions tests/operations/pipx.packages/add_packages.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"args": ["copier==9.0.1", "invoke"],
"args": [["copier==0.9.1", "invoke"]],
"facts": {
"pipx.PipxPackages": {}
"pipx.PipxPackages": {"ensurepath": ["0.1.1"]}
},
"commands": [
"pipx install --force copier==9.0.1",
"pipx install --force copier==0.9.1",
"pipx install --force invoke"
]
}
10 changes: 4 additions & 6 deletions tests/operations/pipx.packages/install_extra_args.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"args": [["pyinfra==1.1", "pytask", "test==1.1"]],
"kwargs": {
"extra_install_args": "--user"
"extra_install_args": "--index-url https://pypi.org/"
},
"facts": {
"pip.PipPackages": {
"pip=pip": {
"pipx.PipxPackages": {
"pyinfra": ["1.0"],
"test": ["1.1"]
}
}
},
},
"commands": [
"pip install --user pyinfra==1.1 pytask"
"pip install --index-url https://pypi.org/ pyinfra==1.1 pytask"
]
}
14 changes: 6 additions & 8 deletions tests/operations/pipx.packages/remove_packages.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"args": [["elasticquery==1.2", "pyinfra", "test==1.1"]],
"args": [["invoke", "copier"]],
"kwargs": {
"present": false
},
"facts": {
"pip.PipPackages": {
"pip=pip": {
"elasticquery": ["1.0"],
"pyinfra": [""],
"test": ["1.1"]
"pipx.PipxPackages": {
"copier": ["9.0.1"],
"invoke": ["2.2.0"]
}
}
},
"commands": [
"pip uninstall --yes pyinfra test==1.1"
"pipx uninstall invoke",
"pipx uninstall copier"
]
}
4 changes: 3 additions & 1 deletion tests/operations/pipx.upgrade_all/upgrade_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"facts": {},
"commands": [
"pipx upgrade-all"
]
],
"idempotent": false,
"disable_idempotent_warning_reason": "package upgrades are always executed"
}

0 comments on commit 4fbec13

Please sign in to comment.