File size: 2,122 Bytes
7f9dfed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
$ErrorActionPreference = "Stop"

$python = ".venv\Scripts\python.exe"
if (-not (Test-Path $python)) {
    $python = "python"
    try {
        & $python --version | Out-Null
    } catch {
        $python = "$env:LOCALAPPDATA\Microsoft\WindowsApps\python3.11.exe"
    }
}
$mypyCache = "$env:TEMP\openbmb-workbench-mypy-cache"
$pipAuditCache = "$env:TEMP\openbmb-workbench-pip-audit-cache"
$pytestCache = "$env:TEMP\openbmb-workbench-pytest-cache"
$coverageFile = "$env:TEMP\openbmb-workbench.coverage"

function Invoke-Checked {
    param(
        [Parameter(Mandatory = $true)]
        [string[]] $Command
    )

    & $Command[0] $Command[1..($Command.Length - 1)]
    if ($LASTEXITCODE -ne 0) {
        throw "Command failed: $($Command -join ' ')"
    }
}

Write-Host "Running tests"
Invoke-Checked @($python, "-m", "unittest", "discover", "-s", "tests", "-p", "test_*.py")

Write-Host "Running app smoke test"
Invoke-Checked @($python, "scripts/smoke_app.py")

Write-Host "Running coverage"
Invoke-Checked @(
    $python,
    "-m",
    "coverage",
    "run",
    "--data-file",
    $coverageFile,
    "-m",
    "unittest",
    "discover",
    "-s",
    "tests",
    "-p",
    "test_*.py"
)
Invoke-Checked @($python, "-m", "coverage", "report", "--data-file", $coverageFile)

Write-Host "Running performance tests"
Invoke-Checked @(
    $python,
    "-m",
    "pytest",
    "tests/performance",
    "-m",
    "performance",
    "-o",
    "cache_dir=$pytestCache"
)

Write-Host "Running ruff"
Invoke-Checked @($python, "-m", "ruff", "check", ".", "--no-cache")

Write-Host "Running mypy"
Invoke-Checked @($python, "-m", "mypy", ".", "--cache-dir", $mypyCache)

Write-Host "Running pylint"
Invoke-Checked @($python, "-m", "pylint", "--persistent=n", "app.py", "core", "datasets", "models", "ui")

Write-Host "Running bandit"
Invoke-Checked @($python, "-m", "bandit", "-r", "app.py", "core", "datasets", "models", "ui")

Write-Host "Running pip-audit"
Invoke-Checked @(
    $python,
    "-m",
    "pip_audit",
    "--cache-dir",
    $pipAuditCache,
    "-r",
    "requirements.txt",
    "-r",
    "requirements-dev.txt"
)