forked from shroominic/codebox-api
-
Notifications
You must be signed in to change notification settings - Fork 0
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
f837cfe
commit 567cc0a
Showing
6 changed files
with
58 additions
and
31 deletions.
There are no files selected for viewing
File renamed without changes.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
import asyncio | ||
import os, sys | ||
from pathlib import Path | ||
|
||
|
||
async def run_example(file: Path): | ||
# Add the examples directory to the path | ||
sys.path.append(str(file.parent)) | ||
|
||
# Run the example | ||
process = await asyncio.create_subprocess_exec("python", file.absolute()) | ||
print(f"Running example {file}...") | ||
await process.wait() | ||
|
||
# check the return code | ||
if process.returncode != 0: | ||
raise Exception(f"Example {file} failed with return code {process.returncode}") | ||
|
||
# Remove the examples directory from the path | ||
sys.path.remove(str(file.parent)) | ||
|
||
|
||
async def run_examples(): | ||
example_files = list(Path("examples").glob("**/*.py")) | ||
# Create a task for each example file | ||
tasks = [asyncio.create_task(run_example(file)) for file in example_files] | ||
# Wait for all tasks to complete | ||
await asyncio.gather(*tasks) | ||
|
||
|
||
def test_run_examples(): | ||
""" Integration test for running the examples. """ | ||
asyncio.run(run_examples()) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_run_examples() |
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,20 @@ | ||
import codeboxapi as cb | ||
|
||
|
||
def test_codebox(): | ||
codebox = cb.CodeBox() | ||
|
||
try: | ||
status = codebox.start() | ||
assert str(status) == "started" | ||
|
||
status = codebox.status() | ||
assert str(status) == "running" | ||
|
||
output = codebox.run("print('Hello World!')") | ||
assert str(output) == "Hello World!\n" | ||
except: | ||
raise | ||
finally: | ||
codebox.stop() | ||
|