-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathpython.Tests.ps1
More file actions
89 lines (78 loc) · 4.15 KB
/
Copy pathpython.Tests.ps1
File metadata and controls
89 lines (78 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Describe 'python' {
BeforeAll {
$env:MISE_PYTHON_GITHUB_ATTESTATIONS = "0"
}
It 'executes python and python3 for 3.12.0' {
mise install python@3.12.0 --force | Out-Null
$installPath = (mise where python@3.12.0).Trim()
(Join-Path $installPath 'python3.exe') | Should -Exist
mise x python@3.12.0 -- where python
mise x python@3.12.0 -- python --version | Should -Be "Python 3.12.0"
$python3Path = (mise x python@3.12.0 -- where python3 | Select-Object -First 1).Trim()
$python3Path | Should -Be (Join-Path $installPath 'python3.exe')
mise x python@3.12.0 -- python3 --version | Should -Be "Python 3.12.0"
}
# https://github.com/jdx/mise/discussions/3821 - python-build-standalone
# ships no pip.exe on Windows, so mise synthesizes pip.cmd/pip3.cmd
It 'synthesizes pip wrappers so pip works out of the box' {
# no-op when the previous test already installed it; keeps this test
# runnable on its own
mise install python@3.12.0 | Out-Null
$installPath = (mise where python@3.12.0).Trim()
(Join-Path $installPath 'pip.cmd') | Should -Exist
(Join-Path $installPath 'pip3.cmd') | Should -Exist
mise x python@3.12.0 -- pip --version
$LASTEXITCODE | Should -Be 0
mise x python@3.12.0 -- pip3 --version
$LASTEXITCODE | Should -Be 0
# Check the actual output through an explicit file handle. Piping a
# batch-file child into the PowerShell pipeline captures nothing on the
# CI runners (a real .exe like python.exe captures fine), so redirect
# to a file instead of asserting on pipeline output.
$out = Join-Path $TestDrive 'pip-version.txt'
$p = Start-Process -FilePath 'mise' -NoNewWindow -Wait -PassThru `
-ArgumentList 'x', 'python@3.12.0', '--', 'pip', '--version' `
-RedirectStandardOutput $out
$p.ExitCode | Should -Be 0
(Get-Content $out -Raw) | Should -Match '^pip \d'
# No separator normalization here on purpose: this doubles as a
# regression test for `file::replace_path`. The windows-e2e job runs with
# `MISE_DATA_DIR=~/.local/share/mise`, which mise used to expand to
# `C:\Users\runneradmin\.local/share/mise` - mixed separators that then
# showed up verbatim in `mise which`/`mise where` output. (`$installPath`
# comes from `mise where`; PowerShell's `Join-Path` folds `/` to `\` in
# its parent argument, so the right-hand side is backslash-only either
# way - which is why only the `mise which` side ever looked wrong.)
$whichPip = (mise which pip --tool python@3.12.0).Trim()
$whichPip | Should -Not -Match '/'
$whichPip | Should -Be (Join-Path $installPath 'pip.cmd')
}
It 'puts Scripts on PATH so pip-installed console scripts run' {
mise install python@3.12.0 | Out-Null
mise x python@3.12.0 -- pip install pycowsay | Out-Null
$LASTEXITCODE | Should -Be 0
$installPath = (mise where python@3.12.0).Trim()
(Join-Path $installPath 'Scripts\pycowsay.exe') | Should -Exist
mise x python@3.12.0 -- pycowsay moo
$LASTEXITCODE | Should -Be 0
}
# https://github.com/jdx/mise/discussions/8872 - default packages used to
# spawn <install>\bin\python (a unix-only path) and silently warn
It 'installs default packages on Windows' {
$pkgFile = Join-Path $TestDrive 'default-python-packages'
Set-Content -Path $pkgFile -Value 'pycowsay'
$env:MISE_PYTHON_DEFAULT_PACKAGES_FILE = $pkgFile
try {
# --force wipes the install dir, so pycowsay from the previous
# test only comes back if default packages actually installed it
mise install python@3.12.0 --force | Out-Null
$installPath = (mise where python@3.12.0).Trim()
(Join-Path $installPath 'Scripts\pycowsay.exe') | Should -Exist
mise x python@3.12.0 -- pycowsay moo
$LASTEXITCODE | Should -Be 0
}
finally {
Remove-Item Env:\MISE_PYTHON_DEFAULT_PACKAGES_FILE -ErrorAction SilentlyContinue
}
}
}