Skip to content

Commit

Permalink
✨ Add examples test script
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Jan 22, 2024
1 parent c257232 commit 0445a53
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/run_examples_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import asyncio
import glob
import subprocess


async def run_script(file_path: str) -> tuple[str, int | None, bytes, bytes]:
"""Run a single script and return the result."""
process = await asyncio.create_subprocess_exec("python", file_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = await process.communicate()
return file_path, process.returncode, stdout, stderr


async def main() -> None:
files: list[str] = glob.glob("example/**/*.py", recursive=True)
tasks: list = [run_script(file) for file in files]
results: list[tuple[str, int | None, bytes, bytes]] = await asyncio.gather(*tasks)

for file, returncode, stdout, stderr in results:
if returncode != 0:
print(f"Error in {file}:")
print(stderr.decode())
else:
print(f"{file} executed successfully.")


def test_examples() -> None:
asyncio.run(main())


if __name__ == "__main__":
test_examples()

0 comments on commit 0445a53

Please sign in to comment.