uv/scripts/scenarios/generate.py
Zanie Blue 1f2112191f
Unpack scenario root requirements in test cases (#757)
As mentioned in #746, instead of just installing the scenario root we
will unpack the root dependencies into the install command to allow
better coverage of direct user requests with scenarios.

I added display of the package tree provided by each scenario.

Use a mustache template for iterative replacements.
2024-01-03 17:31:29 -06:00

56 lines
1.2 KiB
Python

#!/usr/bin/env python3
#
# Generates snapshot test cases from packse scenarios.
#
# Usage:
# $ scripts/scenarios/generate.py > crates/puffin-cli/tests/pip_install_scenarios.rs
try:
import packse
except ImportError:
print("packse must be installed")
exit(1)
try:
import chevron_blue
except ImportError:
print("chevron-blue must be installed")
exit(1)
import sys
import subprocess
import json
from pathlib import Path
__dir__ = Path(__file__).parent
TEMPLATE = __dir__ / "template.mustache"
DATA = __dir__ / "data.json"
data = json.loads(
subprocess.check_output(
[
"packse",
"inspect",
str(packse.__development_base_path__ / "scenarios"),
],
)
)
# Add a generated
data["generated_by"] = f"Generated by `{' '.join(sys.argv)}`"
# Add normalized names for tests
for scenario in data["scenarios"]:
scenario["normalized_name"] = scenario["name"].replace("-", "_")
# Drop the example scenario
for index, scenario in enumerate(data["scenarios"]):
if scenario["name"] == "example":
data["scenarios"].pop(index)
output = chevron_blue.render(template=TEMPLATE.read_text(), data=data, no_escape=True)
print(output)