Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/free-threaded-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ jobs:

- name: Run the tests
run: |
# The data file variables name the files restored above, before
# any test changes folder.
$env:_51DEGREES_DD_PATH = (Resolve-Path cxx/data/device-detection/51Degrees-LiteV4.1.hash).Path
$env:_51DEGREES_IPI_PATH = (Resolve-Path cxx/data/ip-intelligence/51Degrees-LiteV41.ipi).Path
$failed = $false
foreach ($package in 'device-detection/fiftyone_devicedetection_onpremise', 'ip-intelligence/fiftyone_ipintelligence_onpremise') {
Write-Host "::group::$package"
Expand Down
16 changes: 16 additions & 0 deletions ci/free-threaded-python.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ Describe 'free-threaded-python.yml' {
}
}

It 'sets <Variable> to the restored <File> before the tests run' -ForEach @(
@{ Variable = '_51DEGREES_DD_PATH'; File = '51Degrees-LiteV4.1.hash' }
@{ Variable = '_51DEGREES_IPI_PATH'; File = '51Degrees-LiteV41.ipi' }
) {
$paths = Get-Paths (@(Get-Step $script:Fetching[0] 'actions/cache')[0])
$paths | Should -Contain "cxx/data/**/$File"
foreach ($testing in $script:Testing) {
$text = $script:Jobs[$testing] -join "`n"
$set = [regex]::Match($text, ('(?m)^\s+\$env:' + $Variable +
'\s*=\s*\(Resolve-Path cxx/data/[\w-]+/' +
[regex]::Escape($File) + '\)\.Path\s*$'))
$set.Success | Should -BeTrue
$set.Index | Should -BeLessThan $text.IndexOf('python -m pytest')
}
}

It 'caches each of the free data files the tests use' {
$paths = Get-Paths (@(Get-Step $script:Fetching[0] 'actions/cache')[0])
foreach ($file in '51Degrees-LiteV4.1.hash', '51Degrees-LiteV41.ipi',
Expand Down
55 changes: 51 additions & 4 deletions ci/key-names.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ BeforeAll {
$script:Saved = @(
'_51DEGREES_RESOURCE_KEY', '_51DEGREES_RESOURCE_KEY_BESPOKE',
'_51DEGREES_LICENSE_KEY', 'TEMP', 'GITHUB_ENV',
'GITHUB_JOB', 'PYTEST_ADDOPTS')
'GITHUB_JOB', 'PYTEST_ADDOPTS', '_51DEGREES_IPI_PATH',
'_51DEGREES_DD_PATH')

function New-TempFolder {
$path = Join-Path ([IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
Expand Down Expand Up @@ -301,9 +302,23 @@ Describe 'Keys under their _51DEGREES_ names' {
@($calls.Others | Where-Object { $_ }) | Should -BeNullOrEmpty
}

It 'asks common-ci for the Enterprise data file with no key or address, and points the tests at it, in ip-intelligence' {
It 'points the examples at the Lite data file it fetched, in device-detection' {
$repoName = New-ProductRepo 'device-detection' 'fetch-assets.ps1'
Push-Location $script:CommonCi
try {
& (Join-Path $repoName 'ci' 'fetch-assets.ps1')
} finally {
Pop-Location
}

# common-ci runs the tests in the same process as the script, so
# the variable is set in this process.
$env:_51DEGREES_DD_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-LiteV4.1.hash')
$env:_51DEGREES_DD_PATH | Should -Exist
}

It 'asks common-ci for the Enterprise data file with no key or address, in ip-intelligence' {
$repoName = New-ProductRepo 'ip-intelligence' 'fetch-assets.ps1'
$env:GITHUB_ENV = Join-Path $script:CommonCi 'github.env'
Push-Location $script:CommonCi
try {
& (Join-Path $repoName 'ci' 'fetch-assets.ps1')
Expand All @@ -314,7 +329,39 @@ Describe 'Keys under their _51DEGREES_ names' {
$calls = @(Get-Content -Raw (Join-Path $script:CommonCi 'fetch.json') | ConvertFrom-Json)
$calls.Assets | Should -Contain '51Degrees-EnterpriseIpiV41.ipi'
@($calls.Others | Where-Object { $_ }) | Should -BeNullOrEmpty
Get-Content $env:GITHUB_ENV | Should -Match '^_51DEGREES_IPI_PATH=.*51Degrees-EnterpriseIpiV41\.ipi$'
}

It 'points the tests at the Lite data file it fetched, in ip-intelligence' {
$repoName = New-ProductRepo 'ip-intelligence' 'fetch-assets.ps1'
Push-Location $script:CommonCi
try {
& (Join-Path $repoName 'ci' 'fetch-assets.ps1')
} finally {
Pop-Location
}

# The tests and examples accept the Lite file, so they use it.
# common-ci runs the tests in the same process as the script, so
# the variable is set in this process, to the file it fetched.
$calls = @(Get-Content -Raw (Join-Path $script:CommonCi 'fetch.json') | ConvertFrom-Json)
$calls.Assets | Should -Contain '51Degrees-LiteIpiV41.ipi'
$env:_51DEGREES_IPI_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-LiteIpiV41.ipi')
$env:_51DEGREES_IPI_PATH | Should -Exist
}

It 'fetches the device detection Lite data file for the mixed examples, and points them at it, in ip-intelligence' {
$repoName = New-ProductRepo 'ip-intelligence' 'fetch-assets.ps1'
Push-Location $script:CommonCi
try {
& (Join-Path $repoName 'ci' 'fetch-assets.ps1')
} finally {
Pop-Location
}

$calls = @(Get-Content -Raw (Join-Path $script:CommonCi 'fetch.json') | ConvertFrom-Json)
$calls.Assets | Should -Contain '51Degrees-LiteV4.1.hash'
$env:_51DEGREES_DD_PATH | Should -Be (Join-Path $script:CommonCi 'assets' '51Degrees-LiteV4.1.hash')
$env:_51DEGREES_DD_PATH | Should -Exist
}
}

Expand Down
5 changes: 5 additions & 0 deletions device-detection/ci/fetch-assets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ foreach ($asset in $assets) {
default {New-Item -ItemType SymbolicLink -Force -Target "$PWD/assets/$_" -Path "$deviceDetectionData/$_"}
}
}

# The examples read their data file from this variable. common-ci runs the
# tests in the same process as this script, so the variable is set in this
# process, to the Lite file fetched above.
$env:_51DEGREES_DD_PATH = (Resolve-Path "assets/51Degrees-LiteV4.1.hash").Path
15 changes: 9 additions & 6 deletions ip-intelligence/ci/fetch-assets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ if ($env:GITHUB_JOB -eq "PreBuild") {
$assetsDir = "$PSScriptRoot/../assets"
New-Item -ItemType Directory -Force -Path $assetsDir | Out-Null

# The mixed examples use the device detection Lite data file as well, so it
# is fetched here too, for a run that tests IP Intelligence alone.
$assets = '51Degrees-LiteIpiV41.ipi', 'ip-intelligence-evidence.yml',
'51Degrees-EnterpriseIpiV41.ipi'
'51Degrees-EnterpriseIpiV41.ipi', '51Degrees-LiteV4.1.hash'

./steps/fetch-assets.ps1 -Assets $assets

Expand All @@ -34,8 +36,9 @@ $asn = '51Degrees-IPIV4AsnIpiV41.ipi'
./steps/fetch-assets.ps1 -Assets $asn
Copy-Item "assets/$asn" $ipIntelligenceData

# The tests prefer the Enterprise file, which they find through the
# environment variable the test suites read.
if ($env:GITHUB_ENV) {
Write-Output "_51DEGREES_IPI_PATH=$assetsDir/51Degrees-EnterpriseIpiV41.ipi" | Out-File -Append -FilePath $env:GITHUB_ENV -ErrorAction SilentlyContinue
}
# The tests and examples find their data file through the environment
# variable the test suites read. They accept the Lite file, so it is the one
# named. common-ci runs the tests in the same process as this script, so the
# variable is set in this process.
$env:_51DEGREES_IPI_PATH = (Resolve-Path "assets/51Degrees-LiteIpiV41.ipi").Path
$env:_51DEGREES_DD_PATH = (Resolve-Path "assets/51Degrees-LiteV4.1.hash").Path
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def test_runs_from_the_repository_root(self):
folder = os.getcwd()
os.chdir(ROOT)
try:
# The free file is the one under test, so a data file named in
# the environment, as CI names the Enterprise file, is set
# aside.
# The free file the example finds itself is the one under test,
# so a data file named in the environment is set aside.
with mock.patch.dict(os.environ):
for name in (ExampleUtils.IPI_PATH_ENV_VAR,):
os.environ.pop(name, None)
Expand Down
Loading