<commit_before>Param(
    [string]$branchName='master',
    [string]$buildFor='',
    [string]$zuulChange=''
)

$ErrorActionPreference = "Stop"

$projectName = $buildFor.split('/')[-1]

$scriptLocation = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
. "$scriptLocation\config.ps1"
. "$scriptLocation\utils.ps1"

$hasProject = Test-Path $buildDir\$projectName
$hasopenstackLogs = Test-Path $openstackLogs

if ($hasOpenstackLogs -eq $false){
   mkdir $openstackLogs
} else {
    Remove-Item -Recurse -Force "$openstackLogs\*"
}

Add-Type -AssemblyName System.IO.Compression.FileSystem

$pip_conf_content = @"
[global]
index-url = http://10.20.1.8:8080/cloudbase/CI/+simple/
[install]
trusted-host = 10.20.1.8
"@

if ($hasProject -eq $false){
    Get-ChildItem $buildDir
    Get-ChildItem ( Get-Item $buildDir ).Parent.FullName
    Throw "$projectName repository was not found. Please run gerrit-git-prep.sh for this project first"
}

git config --global user.email "<EMAIL>"
git config --global user.name "<NAME>"

pushd C:\

if (Test-Path $pythonArchive) {
   Remove-Item -Force $pythonArchive
}

Invoke-FastWebRequest -Uri http://10.20.1.14:8080/python.zip -OutFile "C:\$pythonArchive"
if (Test-Path $pythonDir)
{
    Cmd /C "rmdir /S /Q $pythonDir"
    #Remove-Item -Recurse -Force $pythonDir
}
Write-Host "Ensure Python folder is up to date"
Write-Host "Extracting archive.."
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\$pythonArchive", "C:\")

popd

$hasPipConf = Test-Path "$env:APPDATA\pip"
if ($hasPipConf -eq $false){
    mkdir "$env:APPDATA\pip"
}
else 
{
    Remove-Item -Recurse -Force "$env:APPDATA\pip\*"
}
Add-Content "$env:APPDATA\pip\pip.ini" $pip_conf_content

$ErrorActionPreference = "Continue"

& easy_install pip
& pip install setuptools
& pip install pymi
& pip install tox
& pip install nose

& pip install pymongo
& pip install python-memcached
& pip install fixtures
& pip install mock
& pip install testresources
& pip install testscenarios

& pip install oslotest


$ErrorActionPreference = "Stop"

ExecRetry {
    GitClonePull "$buildDir\requirements" "https://git.openstack.org/openstack/requirements.git" $branchName
}

ExecRetry {
    pushd "$buildDir\requirements"
    Write-Host "Installing OpenStack/Requirements..."
    & pip install -c upper-constraints.txt -U pbr virtualenv httplib2 prettytable>=0.7 setuptools
    & pip install -c upper-constraints.txt -U .
    if ($LastExitCode) { Throw "Failed to install openstack/requirements from repo" }
    popd
}


ExecRetry {
    pushd $buildDir\$projectName
    & update-requirements.exe --source $buildDir\requirements .
    & pip install -r $buildDir\$projectName\requirements.txt
    if ($LastExitCode) { Throw "Failed to install $projectNameInstall requirements" }
    & pip install -e $buildDir\$projectName
    if ($LastExitCode) { Throw "Failed to install $projectNameInstall from repo" }
    popd
}

if (Test-Path "$buildDir\$projectName\test-requirements.txt")
{
    $ErrorActionPreference = "Continue"
    & pip install -r $buildDir\$projectName\test-requirements.txt
    $ErrorActionPreference = "Stop"
}

$currDate = (Get-Date).ToString()
Write-Host "$currDate Running unit tests."

Try {
    $proc = Start-Job -Name "UnitTests" -ScriptBlock { cd $buildDir\$projectName; & python -m unittest discover 2>&1; Write-Output "Exit code: $LASTEXITCODE" }
} Catch {
    Throw "Could not start the unit tests job."
}

Wait-Job -Timeout 300 -Id $proc.Id

if ($proc.State -eq "Running")
{
   Stop-Job -PassThru -Id $proc.Id | Remove-job
   Throw "Unit tests exceeded time linit of 300 seconds."
}

$result = Receive-Job -Id $proc.Id -ErrorAction Continue
Remove-Job -Id $proc.Id

Add-Content $openstackLogs\unittest__output.txt $result

$exitcode = $result[-1][-1]

$currDate = (Get-Date).ToString()
Write-Host "$currDate Finished running unit tests."
if ($exitcode -ne 0)
{
    Throw "Unit tests result exit code: $exitcode"
} else {
    Write-Host "Unit tests result exit code: $exitcode"
}<commit_msg>Fix type string comparison<commit_after>Param(
    [string]$branchName='master',
    [string]$buildFor='',
    [string]$zuulChange=''
)

$ErrorActionPreference = "Stop"

$projectName = $buildFor.split('/')[-1]

$scriptLocation = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
. "$scriptLocation\config.ps1"
. "$scriptLocation\utils.ps1"

$hasProject = Test-Path $buildDir\$projectName
$hasopenstackLogs = Test-Path $openstackLogs

if ($hasOpenstackLogs -eq $false){
   mkdir $openstackLogs
} else {
    Remove-Item -Recurse -Force "$openstackLogs\*"
}

Add-Type -AssemblyName System.IO.Compression.FileSystem

$pip_conf_content = @"
[global]
index-url = http://10.20.1.8:8080/cloudbase/CI/+simple/
[install]
trusted-host = 10.20.1.8
"@

if ($hasProject -eq $false){
    Get-ChildItem $buildDir
    Get-ChildItem ( Get-Item $buildDir ).Parent.FullName
    Throw "$projectName repository was not found. Please run gerrit-git-prep.sh for this project first"
}

git config --global user.email "<EMAIL>"
git config --global user.name "<NAME>"

pushd C:\

if (Test-Path $pythonArchive) {
   Remove-Item -Force $pythonArchive
}

Invoke-FastWebRequest -Uri http://10.20.1.14:8080/python.zip -OutFile "C:\$pythonArchive"
if (Test-Path $pythonDir)
{
    Cmd /C "rmdir /S /Q $pythonDir"
    #Remove-Item -Recurse -Force $pythonDir
}
Write-Host "Ensure Python folder is up to date"
Write-Host "Extracting archive.."
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\$pythonArchive", "C:\")

popd

$hasPipConf = Test-Path "$env:APPDATA\pip"
if ($hasPipConf -eq $false){
    mkdir "$env:APPDATA\pip"
}
else 
{
    Remove-Item -Recurse -Force "$env:APPDATA\pip\*"
}
Add-Content "$env:APPDATA\pip\pip.ini" $pip_conf_content

$ErrorActionPreference = "Continue"

& easy_install pip
& pip install setuptools
& pip install pymi
& pip install tox
& pip install nose

& pip install pymongo
& pip install python-memcached
& pip install fixtures
& pip install mock
& pip install testresources
& pip install testscenarios

& pip install oslotest


$ErrorActionPreference = "Stop"

ExecRetry {
    GitClonePull "$buildDir\requirements" "https://git.openstack.org/openstack/requirements.git" $branchName
}

ExecRetry {
    pushd "$buildDir\requirements"
    Write-Host "Installing OpenStack/Requirements..."
    & pip install -c upper-constraints.txt -U pbr virtualenv httplib2 prettytable>=0.7 setuptools
    & pip install -c upper-constraints.txt -U .
    if ($LastExitCode) { Throw "Failed to install openstack/requirements from repo" }
    popd
}


ExecRetry {
    pushd $buildDir\$projectName
    & update-requirements.exe --source $buildDir\requirements .
    & pip install -r $buildDir\$projectName\requirements.txt
    if ($LastExitCode) { Throw "Failed to install $projectNameInstall requirements" }
    & pip install -e $buildDir\$projectName
    if ($LastExitCode) { Throw "Failed to install $projectNameInstall from repo" }
    popd
}

if (Test-Path "$buildDir\$projectName\test-requirements.txt")
{
    $ErrorActionPreference = "Continue"
    & pip install -r $buildDir\$projectName\test-requirements.txt
    $ErrorActionPreference = "Stop"
}

$currDate = (Get-Date).ToString()
Write-Host "$currDate Running unit tests."

Try {
    $proc = Start-Job -Name "UnitTests" -ScriptBlock { cd $buildDir\$projectName; & python -m unittest discover 2>&1; Write-Output "Exit code: $LASTEXITCODE" }
} Catch {
    Throw "Could not start the unit tests job."
}

Wait-Job -Timeout 300 -Id $proc.Id

if ($proc.State -eq "Running")
{
   Stop-Job -PassThru -Id $proc.Id | Remove-job
   Throw "Unit tests exceeded time linit of 300 seconds."
}

$result = Receive-Job -Id $proc.Id -ErrorAction Continue
Remove-Job -Id $proc.Id

Add-Content $openstackLogs\unittest__output.txt $result

$exitcode = $result[-1][-1]

$currDate = (Get-Date).ToString()
Write-Host "$currDate Finished running unit tests."
if ($exitcode.ToString() -ne "0")
{
    Throw "Unit tests result exit code: $exitcode"
} else {
    Write-Host "Unit tests result exit code: $exitcode"
}
{'fraction_non_alphanumeric': 0.13509162951956413, 'fraction_numerical': 0.010896483407627538, 'mean_word_length': 4.09589905362776, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '629976', 'n_tokens_mistral': 2801, 'n_tokens_neox': 2698, 'n_words': 691}