python-versions/tests/python-tests.ps1

101 lines
3.8 KiB
PowerShell
Raw Normal View History

param (
[semver] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
$Version,
[string] [Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
$Platform
)
Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1")
Import-Module (Join-Path $PSScriptRoot "../helpers/common-helpers.psm1")
2020-10-13 16:56:27 +00:00
Import-Module (Join-Path $PSScriptRoot "../builders/python-version.psm1")
2022-01-21 09:43:03 +00:00
BeforeAll {
function Analyze-MissingModules([string] $buildOutputLocation) {
$searchStringStart = "Failed to build these modules:"
$searchStringEnd = "running build_scripts"
$pattern = "$searchStringStart(.*?)$searchStringEnd"
2022-01-21 09:43:03 +00:00
$buildContent = Get-Content -Path $buildOutputLocation
$splitBuiltOutput = $buildContent -split "\n";
2022-01-21 09:43:03 +00:00
### Search for missing modules that are displayed between the search strings
$regexMatch = [regex]::match($SplitBuiltOutput, $Pattern)
if ($regexMatch.Success)
{
$module = $regexMatch.Groups[1].Value.Trim()
Write-Host "Failed missing modules:"
Write-Host $module
if ( ($module -eq "_tkinter") -and ( [semver]"$($Version.Major).$($Version.Minor)" -ge [semver]"3.10" -and $Version.PreReleaseLabel ) ) {
Write-Host "$module $Version ignored"
} else {
return 1
}
2021-03-05 18:00:49 +00:00
}
2022-01-21 09:43:03 +00:00
return 0
}
}
Describe "Tests" {
It "Python version" {
"python --version" | Should -ReturnZeroExitCode
$pythonLocation = (Get-Command "python").Path
$pythonLocation | Should -Not -BeNullOrEmpty
$expectedPath = Join-Path -Path $env:RUNNER_TOOL_CACHE -ChildPath "Python"
$pythonLocation.startsWith($expectedPath) | Should -BeTrue
}
It "Run simple code" {
"python ./sources/simple-test.py" | Should -ReturnZeroExitCode
}
if (($Version -ge "3.2.0") -and -not ([semver]"$($Version.Major).$($Version.Minor)" -eq [semver]"3.11" -and $Version.PreReleaseLabel)) {
It "Check if sqlite3 module is installed" {
"python ./sources/python-sqlite3.py" | Should -ReturnZeroExitCode
}
}
2020-10-20 10:12:41 +00:00
It "Run pip" {
"pip install requests" | Should -ReturnZeroExitCode
2020-10-20 12:47:44 +00:00
"pip uninstall requests -y" | Should -ReturnZeroExitCode
2020-10-20 10:12:41 +00:00
}
if (IsNixPlatform $Platform) {
It "Check for failed modules in build_output" {
$buildOutputLocation = Join-Path $env:RUNNER_TEMP "build_output.txt"
Analyze-MissingModules $buildOutputLocation | Should -Be 0
}
It "Check if all required python modules are installed" {
"python ./sources/python-modules.py" | Should -ReturnZeroExitCode
}
It "Check if python configuration is correct" {
2020-10-13 16:56:27 +00:00
$nativeVersion = Convert-Version -version $Version
"python ./sources/python-config-test.py $Version $nativeVersion" | Should -ReturnZeroExitCode
}
It "Check if shared libraries are linked correctly" {
"bash ./sources/psutil-install-test.sh" | Should -ReturnZeroExitCode
}
}
# Pyinstaller 3.5 does not support Python 3.8.0. Check issue https://github.com/pyinstaller/pyinstaller/issues/4311
if ($Version -lt "3.8.0" -and $Version.Major -ne "2") {
It "Validate Pyinstaller" {
"pip install pyinstaller" | Should -ReturnZeroExitCode
"pyinstaller --onefile ./sources/simple-test.py" | Should -ReturnZeroExitCode
"./dist/simple-test" | Should -ReturnZeroExitCode
}
}
2022-06-17 09:50:52 +00:00
if (($Platform -match "macos") -or ($Platform -match "darwin")) {
if ($Version -gt "3.7.12" ) {
It "Check if python above 3.7.12 use tcl/tk v8.6" {
"python ./sources/tcltk-86.py" | Should -ReturnZeroExitCode
}
}
}
2021-03-05 18:00:49 +00:00
}