diff --git a/examples/async_file_io.py b/examples/async/file_io.py similarity index 100% rename from examples/async_file_io.py rename to examples/async/file_io.py diff --git a/examples/async_dataset.py b/examples/async/plot_dataset.py similarity index 97% rename from examples/async_dataset.py rename to examples/async/plot_dataset.py index 93086a6..3debf2b 100755 --- a/examples/async_dataset.py +++ b/examples/async/plot_dataset.py @@ -4,6 +4,7 @@ async def main(): async with CodeBox() as codebox: + raise NotImplementedError("This example is not working yet") # download the iris dataset csv_bytes = requests.get("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data").content diff --git a/tests/create_test.py b/tests/create_test.py deleted file mode 100644 index ba4806b..0000000 --- a/tests/create_test.py +++ /dev/null @@ -1,16 +0,0 @@ -import codeboxapi as cb - - -def test_create_codebox(): - codebox = cb.CodeBox() - status = codebox.start() - assert status.status == "started" - - status = codebox.status() - assert status.status == "running" - - codebox.stop() - - # status = codebox.status() - # assert status.status == "stopped" - # TODO: Fix this test diff --git a/tests/hello_world_test.py b/tests/hello_world_test.py deleted file mode 100644 index d80b5d3..0000000 --- a/tests/hello_world_test.py +++ /dev/null @@ -1,15 +0,0 @@ -import codeboxapi as cb - - -def test_create_codebox(): - codebox = cb.CodeBox() - - status = codebox.start() - assert status.status == "started" - - output = codebox.run( - "print('Hello World!')" - ) - assert output.content == "Hello World!\n" - - codebox.stop() diff --git a/tests/run_examples_test.py b/tests/run_examples_test.py new file mode 100644 index 0000000..ef26541 --- /dev/null +++ b/tests/run_examples_test.py @@ -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() diff --git a/tests/simple_test.py b/tests/simple_test.py new file mode 100644 index 0000000..58621ed --- /dev/null +++ b/tests/simple_test.py @@ -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() + \ No newline at end of file