Skip to content

Commit 6e48d86

Browse files
Handle dynamic paths
1 parent 6c3b94a commit 6e48d86

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

shared/python/show_soft_deleted_resources.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,25 @@
66
import sys
77
import argparse
88
from datetime import datetime
9+
from pathlib import Path
910

1011
# APIM Samples imports
1112
import azure_resources as az
1213

1314

15+
def _get_suggested_purge_command() -> str:
16+
"""Return a purge command that works from the current working directory."""
17+
18+
script_path = Path(__file__).resolve()
19+
cwd_path = Path.cwd().resolve()
20+
21+
try:
22+
rel_path = script_path.relative_to(cwd_path)
23+
return f'python {rel_path.as_posix()} --purge'
24+
except ValueError:
25+
return f'python "{script_path}" --purge'
26+
27+
1428
def parse_date(date_str: str) -> str:
1529
"""Parse and format date string for display."""
1630
if not date_str:
@@ -349,7 +363,7 @@ def main():
349363
print('\n❌ Purge operation cancelled')
350364
else:
351365
print('\n💡 To purge all these resources, run:')
352-
print(' python shared/python/show_soft_deleted_resources.py --purge')
366+
print(f' {_get_suggested_purge_command()}')
353367

354368
print()
355369
return 0

tests/python/run_tests.ps1

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
# PowerShell script to run pytest with coverage and store .coverage in tests/python
2-
$env:COVERAGE_FILE = "tests/python/.coverage"
3-
pytest -v --cov=shared/python --cov-config=tests/python/.coveragerc --cov-report=html:tests/python/htmlcov tests/python/
1+
#!/usr/bin/env pwsh
2+
3+
# PowerShell script to run pytest with coverage.
4+
# This script can be run from any working directory.
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
$ScriptDir = $PSScriptRoot
9+
$RepoRoot = (Resolve-Path (Join-Path $ScriptDir "..\.."))
10+
11+
Push-Location $RepoRoot
12+
try {
13+
$env:COVERAGE_FILE = (Join-Path $RepoRoot "tests/python/.coverage")
14+
pytest -v --cov=shared/python --cov-config=tests/python/.coveragerc --cov-report=html:tests/python/htmlcov tests/python/
15+
}
16+
finally {
17+
Pop-Location
18+
}

tests/python/run_tests.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# Shell script to run pytest with coverage and store .coverage in tests/python
2-
COVERAGE_FILE=tests/python/.coverage
3-
export COVERAGE_FILE
1+
#!/usr/bin/env bash
2+
3+
# Shell script to run pytest with coverage.
4+
# This script can be run from any working directory.
5+
6+
set -euo pipefail
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
10+
11+
cd "${REPO_ROOT}"
12+
13+
export COVERAGE_FILE="tests/python/.coverage"
414
pytest -v --cov=shared/python --cov-config=tests/python/.coveragerc --cov-report=html:tests/python/htmlcov tests/python/

0 commit comments

Comments
 (0)