|
| 1 | +import os |
| 2 | +import shutil |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +pytestmark = pytest.mark.skipif(sys.platform != "win32", reason="Windows-only e2e") |
| 10 | + |
| 11 | +REPO_ROOT = Path(__file__).resolve().parents[2] |
| 12 | +EXAMPLE_PLAIN = REPO_ROOT / "examples" / "example_hello_world_python" / "hello_world_python.plain" |
| 13 | + |
| 14 | +# if it takes longer, it's stuck |
| 15 | +RENDER_TIMEOUT_SECONDS = 180 |
| 16 | + |
| 17 | + |
| 18 | +def test_render_and_run_hello_world_python_windows(codeplain_exe: Path, api_key: str, tmp_path: Path): |
| 19 | + shutil.copy(EXAMPLE_PLAIN, tmp_path / "hello_world_python.plain") |
| 20 | + |
| 21 | + env = {**os.environ, "CODEPLAIN_API_KEY": api_key} |
| 22 | + |
| 23 | + result = subprocess.run( |
| 24 | + [str(codeplain_exe), "--help"], |
| 25 | + capture_output=True, |
| 26 | + text=True, |
| 27 | + timeout=60, |
| 28 | + env=env, |
| 29 | + check=False, |
| 30 | + ) |
| 31 | + assert result.returncode == 0, ( |
| 32 | + f"codeplain --help failed:\nstdout:\n{result.stdout}\nstderr:\n{result.stderr}" |
| 33 | + ) |
| 34 | + |
| 35 | + result = subprocess.run( |
| 36 | + [ |
| 37 | + str(codeplain_exe), |
| 38 | + "--headless", |
| 39 | + "--build-folder", |
| 40 | + "build/", |
| 41 | + "hello_world_python.plain", |
| 42 | + ], |
| 43 | + cwd=tmp_path, |
| 44 | + capture_output=True, |
| 45 | + text=True, |
| 46 | + timeout=RENDER_TIMEOUT_SECONDS, |
| 47 | + env=env, |
| 48 | + check=False, |
| 49 | + ) |
| 50 | + assert result.returncode == 0, ( |
| 51 | + f"codeplain render failed (rc={result.returncode}):\n" |
| 52 | + f"stdout:\n{result.stdout}\nstderr:\n{result.stderr}" |
| 53 | + ) |
| 54 | + |
| 55 | + generated = tmp_path / "build" / "hello_world_python" / "hello_world.py" |
| 56 | + assert generated.exists(), f"expected generated file at {generated} but it was not produced" |
| 57 | + |
| 58 | + result = subprocess.run( |
| 59 | + ["python", str(generated)], |
| 60 | + capture_output=True, |
| 61 | + text=True, |
| 62 | + timeout=30, |
| 63 | + env=env, |
| 64 | + check=False, |
| 65 | + ) |
| 66 | + assert result.returncode == 0, ( |
| 67 | + f"generated python failed (rc={result.returncode}):\nstderr:\n{result.stderr}" |
| 68 | + ) |
| 69 | + assert "hello, world" in result.stdout.lower(), ( |
| 70 | + f"unexpected stdout from generated app: {result.stdout!r}" |
| 71 | + ) |
0 commit comments