Add validate-feed helper script
This commit is contained in:
parent
939cd9ea5d
commit
dce67ea9e3
3 changed files with 80 additions and 0 deletions
67
tests/test_validate_feed_script.py
Normal file
67
tests/test_validate_feed_script.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import os
|
||||
import stat
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_validate_feed_script_changes_to_feedvalidator_and_forwards_args(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
script_path = Path(__file__).resolve().parents[1] / "scripts" / "validate-feed"
|
||||
feedvalidator_dir = tmp_path / "feedvalidator"
|
||||
bin_dir = tmp_path / "bin"
|
||||
caller_dir = tmp_path / "caller"
|
||||
feed_path = caller_dir / "path" / "to" / "feed.rss"
|
||||
trace_dir = tmp_path / "trace"
|
||||
|
||||
feedvalidator_dir.mkdir()
|
||||
bin_dir.mkdir()
|
||||
feed_path.parent.mkdir(parents=True)
|
||||
feed_path.write_text("<rss/>", encoding="utf-8")
|
||||
trace_dir.mkdir()
|
||||
|
||||
uv_path = bin_dir / "uv"
|
||||
uv_path.write_text(
|
||||
"""#!/bin/sh
|
||||
printf '%s\\n' "$PWD" > "$TRACE_DIR/cwd"
|
||||
printf '%s\\n' "$@" > "$TRACE_DIR/args"
|
||||
printf 'validator output\\n'
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
uv_path.chmod(uv_path.stat().st_mode | stat.S_IXUSR)
|
||||
|
||||
pager_path = bin_dir / "pager"
|
||||
pager_path.write_text(
|
||||
"""#!/bin/sh
|
||||
cat > "$TRACE_DIR/pager-input"
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
pager_path.chmod(pager_path.stat().st_mode | stat.S_IXUSR)
|
||||
|
||||
env = os.environ.copy()
|
||||
env["FEEDVALIDATOR_DIR"] = str(feedvalidator_dir)
|
||||
env["PAGER"] = str(pager_path)
|
||||
env["PATH"] = f"{bin_dir}:{env['PATH']}"
|
||||
env["TRACE_DIR"] = str(trace_dir)
|
||||
|
||||
subprocess.run(
|
||||
[str(script_path), "path/to/feed.rss", "--flag"],
|
||||
check=True,
|
||||
env=env,
|
||||
cwd=caller_dir,
|
||||
)
|
||||
|
||||
assert (trace_dir / "cwd").read_text(encoding="utf-8").strip() == str(
|
||||
feedvalidator_dir
|
||||
)
|
||||
assert (trace_dir / "args").read_text(encoding="utf-8").splitlines() == [
|
||||
"run",
|
||||
"validate_feed.py",
|
||||
str(feed_path.resolve()),
|
||||
"--flag",
|
||||
]
|
||||
assert (trace_dir / "pager-input").read_text(
|
||||
encoding="utf-8"
|
||||
) == "validator output\n"
|
||||
Loading…
Add table
Add a link
Reference in a new issue