-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
run-tests.ps1
110 lines (95 loc) · 3.3 KB
/
run-tests.ps1
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
$HasTestsDir = Test-Path -Path tests -PathType Container
$HasProjectDir = Test-Path -Path yamlpath -PathType Container
if (-Not $HasTestsDir -Or -Not $HasProjectDir) {
Write-Error "Please start this script only from within the top directory of the YAML Path project."
exit 2
}
# Credit: https://stackoverflow.com/a/54935264
function New-TemporaryDirectory {
[CmdletBinding(SupportsShouldProcess = $true)]
param()
$parent = [System.IO.Path]::GetTempPath()
do {
$name = [System.IO.Path]::GetRandomFileName()
$item = New-Item -Path $parent -Name $name -ItemType "directory" -ErrorAction SilentlyContinue
} while (-not $item)
return $Item
}
$EnvDirs = Get-ChildItem -Directory -Filter "venv*"
ForEach ($EnvDir in $EnvDirs) {
& "$($EnvDir.FullName)\Scripts\Activate.ps1"
if (!$?) {
Write-Error "`nERROR: Unable to activate $EnvDir!"
continue
}
$PythonVersion = $(python --version)
Write-Output @"
=========================================================================
Using Python $PythonVersion...
=========================================================================
"@
Write-Output "...spawning a new temporary Virtual Environment..."
$TmpVEnv = New-TemporaryDirectory
python -m venv $TmpVEnv
if (!$?) {
Write-Error "`nERROR: Unable to spawn a new temporary virtual environment at $TmpVEnv!"
exit 125
}
& deactivate
& "$($TmpVEnv.FullName)\Scripts\Activate.ps1"
if (!$?) {
Write-Error "`nERROR: Unable to activate $TmpVEnv!"
continue
}
Write-Output "...upgrading pip"
python -m pip install --upgrade pip
Write-Output "...upgrading setuptools"
pip install --upgrade setuptools
Write-Output "...upgrading wheel"
pip install --upgrade wheel
Write-Output "...installing self"
pip install --editable .
if (!$?) {
& deactivate
Remove-Item -Recurse -Force $TmpVEnv
Write-Error "`nERROR: Unable to install self!"
exit 124
}
Write-Output "...upgrading testing tools"
pip install --upgrade mypy pytest pytest-cov pytest-console-scripts pylint coveralls pydocstyle
Write-Output "`nPYDOCSTYLE..."
pydocstyle yamlpath | Out-String
if (!$?) {
& deactivate
Remove-Item -Recurse -Force $TmpVEnv
Write-Error "PYDOCSTYLE Error: $?"
exit 9
}
Write-Output "`nMYPY..."
mypy yamlpath | Out-String
if (!$?) {
& deactivate
Remove-Item -Recurse -Force $TmpVEnv
Write-Error "MYPY Error: $?"
exit 10
}
Write-Output "`nPYLINT..."
pylint yamlpath | Out-String
if (!$?) {
& deactivate
Remove-Item -Recurse -Force $TmpVEnv
Write-Error "PYLINT Error: $?"
exit 11
}
Write-Output "`n PYTEST..."
pytest -vv --cov=yamlpath --cov-report=term-missing --cov-fail-under=100 --script-launch-mode=subprocess tests
if (!$?) {
& deactivate
Remove-Item -Recurse -Force $TmpVEnv
Write-Error "PYTEST Error: $?"
exit 12
}
Write-Output "Deactivating virtual Python environment..."
& deactivate
Remove-Item -Recurse -Force $TmpVEnv
}