|
| 1 | +import subprocess |
| 2 | +from pathlib import Path |
| 3 | +from tempfile import TemporaryDirectory |
| 4 | + |
| 5 | +## VIASH START |
| 6 | +meta = { |
| 7 | + "executable": "foo", |
| 8 | +} |
| 9 | +## VIASH END |
| 10 | + |
| 11 | +task_template_repo = "https://github.com/openproblems-bio/task_template.git" |
| 12 | + |
| 13 | +with TemporaryDirectory() as tmpdir: |
| 14 | + tmpdir_path = Path(tmpdir) |
| 15 | + task_template_path = tmpdir_path / "task_template" |
| 16 | + input_path = task_template_path / "src" / "api" |
| 17 | + output_path = Path(tmpdir) / "README.md" |
| 18 | + qmd_path = Path(tmpdir) / "README.qmd" |
| 19 | + |
| 20 | + clone_cmd = [ |
| 21 | + "git", |
| 22 | + "clone", |
| 23 | + "--depth", |
| 24 | + "1", |
| 25 | + task_template_repo, |
| 26 | + str(task_template_path), |
| 27 | + ] |
| 28 | + |
| 29 | + print(">> Cloning task_template", flush=True) |
| 30 | + clone_out = subprocess.run(clone_cmd, capture_output=True, text=True) |
| 31 | + |
| 32 | + if clone_out.stdout: |
| 33 | + print(clone_out.stdout) |
| 34 | + if clone_out.stderr: |
| 35 | + print(clone_out.stderr) |
| 36 | + |
| 37 | + if clone_out.returncode: |
| 38 | + print(f"script: '{' '.join(clone_cmd)}' exited with an error.") |
| 39 | + exit(clone_out.returncode) |
| 40 | + |
| 41 | + cmd = [ |
| 42 | + meta["executable"], |
| 43 | + "--input", |
| 44 | + str(input_path), |
| 45 | + "--output", |
| 46 | + str(output_path), |
| 47 | + ] |
| 48 | + |
| 49 | + print(">> Running the script as test", flush=True) |
| 50 | + out = subprocess.run(cmd, capture_output=True, text=True) |
| 51 | + |
| 52 | + if out.stdout: |
| 53 | + print(out.stdout) |
| 54 | + if out.stderr: |
| 55 | + print(out.stderr) |
| 56 | + |
| 57 | + if out.returncode: |
| 58 | + print(f"script: '{' '.join(cmd)}' exited with an error.") |
| 59 | + exit(out.returncode) |
| 60 | + |
| 61 | + print(">> Checking whether output files exist", flush=True) |
| 62 | + assert output_path.exists(), "README.md was not generated" |
| 63 | + assert qmd_path.exists(), "README.qmd was not generated" |
| 64 | + |
| 65 | + print(">> Checking file contents", flush=True) |
| 66 | + output_lines = output_path.read_text().splitlines() |
| 67 | + qmd_lines = qmd_path.read_text().splitlines() |
| 68 | + |
| 69 | + assert any("## Description" in line for line in output_lines), "README.md is missing description section" |
| 70 | + assert any("flowchart TB" in line for line in output_lines), "README.md is missing task graph" |
| 71 | + assert any("## File format:" in line for line in output_lines), "README.md is missing file format section" |
| 72 | + assert any("format: gfm" in line for line in qmd_lines), "README.qmd header is missing gfm format" |
| 73 | + |
| 74 | +print("All checks succeeded!", flush=True) |
0 commit comments