Skip to content

Commit

Permalink
add: unit tests for PowerShell (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
metaist committed Aug 28, 2024
1 parent a5d3ca9 commit 7ce4218
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"prebuild",
"pushd",
"putenv",
"pwsh",
"pypa",
"pypi",
"pyproject",
Expand Down
2 changes: 1 addition & 1 deletion src/ds/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def venv_activate_cmd(venv: Path) -> str:
return f"source {venv / 'bin' / 'activate.csh'};"
if sys.platform.startswith("linux") or sys.platform.startswith("darwin"):
if is_powershell: # POSIX
return str(venv / "bin" / "Activate.ps1")
return f"source {venv / "bin" / "Activate.ps1"};"
return default

# no cover: start
Expand Down
17 changes: 14 additions & 3 deletions test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# std
from pathlib import Path
import os

# pkg
from ds.args import Args
Expand All @@ -22,11 +23,21 @@ def test_venv_activate() -> None:
assert venv_activate_cmd(venv) == "source .venv/bin/activate.csh;"
with TempEnv(SHELL="/bin/fish"):
assert venv_activate_cmd(venv) == "source .venv/bin/activate.fish;"

# handle unknown linux / macOS shell
with TempEnv(SHELL="/bin/unknown"):
with TempEnv(SHELL="/bin/unknown"): # unknown POSIX
assert venv_activate_cmd(venv) == "source .venv/bin/activate;"

# simulate PowerShell
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.4
folders = os.pathsep.join(
[
"$HOME/.local/share/powershell/Modules",
"/usr/local/share/powershell/Modules",
"/opt/microsoft/powershell/6/Modules",
]
)
with TempEnv(SHELL="/usr/bin/pwsh", PSModulePath=folders):
assert venv_activate_cmd(venv) == "source .venv/bin/Activate.ps1;"


def test_run_composite() -> None:
"""Run a composite test."""
Expand Down

0 comments on commit 7ce4218

Please sign in to comment.