Skip to content

Commit

Permalink
🧪 improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Jul 31, 2023
1 parent f837cfe commit 567cc0a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 31 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 0 additions & 16 deletions tests/create_test.py

This file was deleted.

15 changes: 0 additions & 15 deletions tests/hello_world_test.py

This file was deleted.

37 changes: 37 additions & 0 deletions tests/run_examples_test.py
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()
20 changes: 20 additions & 0 deletions tests/simple_test.py
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()

0 comments on commit 567cc0a

Please sign in to comment.