Skip to content

Commit

Permalink
58 test the notebooks (#60)
Browse files Browse the repository at this point in the history
* towards testing notebooks

* testing notebooks

* fmt
  • Loading branch information
tschm authored Feb 15, 2025
1 parent 019e9fd commit 8633fd6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/act.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ jobs:
with:
working-directory: template
workflow: pre-commit.yml

- name: Test ci flow
uses: cvxgrp/cradle/actions/flow@main
with:
working-directory: template
workflow: ci.yml
25 changes: 25 additions & 0 deletions template/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "ci"

on:
- push

jobs:
test:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ '3.10', '3.11', '3.12', '3.13' ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: "Build the virtual environment"
uses: cvxgrp/.github/actions/environment@v2.2.3
with:
python-version: ${{ matrix.python-version }}

- uses: cvxgrp/.github/actions/test@v2.2.3
with:
tests-folder: tests
14 changes: 14 additions & 0 deletions template/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path

import pytest


@pytest.fixture(scope="session", name="resource_dir")
def resource_fixture() -> Path:
"""resource fixture"""
return Path(__file__).parent / "resources"


@pytest.fixture(name="root_dir")
def root_fixture(resource_dir: Path) -> Path:
return resource_dir.parent.parent
Empty file.
24 changes: 24 additions & 0 deletions template/tests/test_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import subprocess


def test_notebooks(root_dir):
# loop over all notebooks
path = root_dir / "notebooks"

# List all .py files in the directory using glob
py_files = list(path.glob("*.py"))

# Loop over the files and run them
for py_file in py_files:
print(f"Running {py_file.name}...")
result = subprocess.run(
["python", str(py_file)], capture_output=True, text=True
)

# Print the result of running the Python file
if result.returncode == 0:
print(f"{py_file.name} ran successfully.")
print(f"Output: {result.stdout}")
else:
print(f"Error running {py_file.name}:")
print(f"stderr: {result.stderr}")

0 comments on commit 8633fd6

Please sign in to comment.