-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c257232
commit 0445a53
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |