Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a CI workflow that runs the examples #7

Merged
merged 11 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build and test starbars

on: [push, pull_request]

jobs:
build:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
matplotlib: ["matplotlib==3.9.0"]
seaborn: ["seaborn==0.13.0"]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-

- name: Install dependencies & self
run: |
# Install latest pip
pip install --upgrade pip
# Install starbars
pip install -e .[test]
# Install matplotlib
pip install ${{ matrix.matplotlib }}
# Install seaborn
pip install ${{ matrix.seaborn }}
# Fix numpy version
pip install numpy~=1.20

- name: Run tests & coverage
run: pytest --cov=starbars

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ docs = [
"sphinx~=7.0",
"matplotlib~=3.9"
]
test = [
"pytest",
"pytest-cov",
"pandas",
"seaborn",
"scipy"
]

[project.urls]
Home = "https://github.com/elide-b/starbars"
Expand Down
20 changes: 20 additions & 0 deletions tests/test_annotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import glob
import os
from pathlib import Path
import importlib.util

import pytest


@pytest.mark.parametrize(
"example", glob.glob(str(Path(__file__).parent.parent / "examples" / "*.py"))
)
def test_example_runnable(example):
# Load the example file as the starbars.__tests__.{name} module
name = example.split(os.sep)[-1].split(".")[0]
modname = f"starbars.__tests__.{name}"
spec = importlib.util.spec_from_file_location(modname, example)
module = importlib.util.module_from_spec(spec)

# Execute the example file
spec.loader.exec_module(module)