|
| 1 | +name: Apply pytest chapter synchronization |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - phase-09-pytest-testing-contracts |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + sync-and-validate: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 15 |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Check out branch |
| 18 | + uses: actions/checkout@v6 |
| 19 | + with: |
| 20 | + ref: phase-09-pytest-testing-contracts |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v6 |
| 25 | + with: |
| 26 | + python-version: "3.13" |
| 27 | + |
| 28 | + - name: Install external-library dependencies |
| 29 | + run: python -m pip install --disable-pip-version-check -r requirements-external.txt |
| 30 | + |
| 31 | + - name: Show dependency versions |
| 32 | + run: | |
| 33 | + python --version |
| 34 | + python - <<'PY' |
| 35 | + import openpyxl |
| 36 | + import pandas |
| 37 | + import pytest |
| 38 | + import requests |
| 39 | + print("pandas", pandas.__version__) |
| 40 | + print("openpyxl", openpyxl.__version__) |
| 41 | + print("requests", requests.__version__) |
| 42 | + print("pytest", pytest.__version__) |
| 43 | + assert pytest.__version__.startswith("9.1.") |
| 44 | + PY |
| 45 | +
|
| 46 | + - name: Synchronize Phase 9 pytest chapter |
| 47 | + run: | |
| 48 | + python scripts/sync_phase09_pytest.py |
| 49 | + python - <<'PY' |
| 50 | + import re |
| 51 | + from pathlib import Path |
| 52 | +
|
| 53 | + paths = [ |
| 54 | + Path("external-libraries/04-pytest/README.md"), |
| 55 | + Path("external-libraries/04-pytest/README.pt-BR.md"), |
| 56 | + Path("external-libraries/04-pytest/README.es.md"), |
| 57 | + ] |
| 58 | + texts = [path.read_text(encoding="utf-8") for path in paths] |
| 59 | + sections = [len(re.findall(r"^## \d+\.", text, flags=re.MULTILINE)) for text in texts] |
| 60 | + blocks = [re.findall(r"```python\n(.*?)```", text, flags=re.DOTALL) for text in texts] |
| 61 | + if sections != [97, 97, 97]: |
| 62 | + raise SystemExit(f"unexpected section counts: {sections}") |
| 63 | + if not (blocks[0] == blocks[1] == blocks[2]): |
| 64 | + raise SystemExit("Python fenced blocks differ across languages") |
| 65 | + print("pytest sections:", sections[0]) |
| 66 | + print("pytest Python blocks:", len(blocks[0])) |
| 67 | + manifest = Path("scripts/example_manifest.txt").read_text(encoding="utf-8").splitlines() |
| 68 | + print("approved examples after sync:", len([line for line in manifest if line.strip()])) |
| 69 | + PY |
| 70 | +
|
| 71 | + - name: Compile Python files |
| 72 | + run: python -m compileall -q -x '(^|/)\.git/' . |
| 73 | + |
| 74 | + - name: Run repository unittest suite |
| 75 | + run: python -m unittest discover -s tests -p 'test_*.py' |
| 76 | + |
| 77 | + - name: Run repository tests with pytest |
| 78 | + run: python -m pytest -q tests |
| 79 | + |
| 80 | + - name: Run approved examples |
| 81 | + run: python scripts/run_examples.py |
| 82 | + |
| 83 | + - name: Verify pytest example outputs |
| 84 | + run: | |
| 85 | + python - <<'PY' |
| 86 | + from pathlib import Path |
| 87 | + import subprocess |
| 88 | + import sys |
| 89 | +
|
| 90 | + root = Path("external-libraries/04-pytest/examples") |
| 91 | + expected = { |
| 92 | + "assertions_and_parametrize.py": "exit code: 0\npassed: 4\n", |
| 93 | + "capture_output_and_logs.py": "exit code: 0\npassed: 2\n", |
| 94 | + "exceptions_and_warnings.py": "exit code: 0\npassed: 2\n", |
| 95 | + "fixtures_and_tmp_path.py": "exit code: 0\npassed: 2\n", |
| 96 | + "monkeypatch_environment.py": "exit code: 0\npassed: 2\n", |
| 97 | + } |
| 98 | + for name, wanted in expected.items(): |
| 99 | + result = subprocess.run( |
| 100 | + [sys.executable, str(root / name)], |
| 101 | + check=True, |
| 102 | + capture_output=True, |
| 103 | + text=True, |
| 104 | + timeout=30, |
| 105 | + ) |
| 106 | + if result.stdout != wanted: |
| 107 | + raise SystemExit(f"{name}: unexpected output\n{result.stdout!r}\n!=\n{wanted!r}") |
| 108 | + if result.stderr: |
| 109 | + raise SystemExit(f"{name}: unexpected stderr\n{result.stderr}") |
| 110 | + print(name, "OK") |
| 111 | + PY |
| 112 | +
|
| 113 | + - name: Check internal Markdown links |
| 114 | + run: python scripts/check_internal_links.py |
| 115 | + |
| 116 | + - name: Validate repository structure |
| 117 | + run: python scripts/validate_repository_structure.py |
| 118 | + |
| 119 | + - name: Check diff whitespace |
| 120 | + run: git diff --check |
| 121 | + |
| 122 | + - name: Remove temporary synchronization tooling |
| 123 | + run: | |
| 124 | + rm scripts/sync_phase09_pytest.py |
| 125 | + rm .github/workflows/apply-phase09-pytest.yml |
| 126 | + git diff --check |
| 127 | +
|
| 128 | + - name: Commit synchronized chapter |
| 129 | + run: | |
| 130 | + git config user.name "Ramon Rodriguez" |
| 131 | + git config user.email "ramoncorreka@hotmail.com" |
| 132 | + git add -A |
| 133 | + if git diff --cached --quiet; then |
| 134 | + echo "No synchronized changes to commit." |
| 135 | + exit 0 |
| 136 | + fi |
| 137 | + git commit -m "Synchronize Phase 9 pytest chapter" |
| 138 | + git push origin HEAD:phase-09-pytest-testing-contracts |
0 commit comments