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

Freerb/cangen action test #358

Closed
wants to merge 6 commits into from
Closed
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
58 changes: 58 additions & 0 deletions .github/workflows/cangen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: cangen
run-name: ${{ github.actor }} is formatting and testing cangen
on:
pull_request:
paths:
- 'scripts/cangen/**'
defaults:
run:
working-directory: scripts/cangen
jobs:
cangen_check:
strategy:
matrix:
python-version: ["3.10", "3.13"]
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.local
key: poetry-0
- name: Configure Cached Poetry
if: steps.cached-poetry.outputs.cache-hit == 'true'
run: |
poetry config virtualenvs.in-project true
poetry config virtualenvs.path true
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true
virtualenvs-path: .venv
- name: Load cached virtual environment
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install cangen dependencies
run: poetry install --no-interaction --no-root # Install dependencies before cangen to help isolate errors.
- name: Install cangen
run: poetry install --no-interaction
- name: Activate virtual environment
run: source .venv/bin/activate
- name: Run tests
run: poetry run pytest
- name: Verify formatting
run: poetry run ruff format --diff
4 changes: 2 additions & 2 deletions scripts/cangen/tests/test_traffic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from cangen.traffic import calculate_bus_load, CANMessage
import pytest
from cangen.traffic import CANMessage, calculate_bus_load


def test_no_messages():
Expand All @@ -13,7 +13,7 @@ def test_normal_messages():
CANMessage(data_length=5, frequency=50),
],
500000,
) == pytest.approx(3.60, rel=1e-2)
) == pytest.approx(3.7, rel=1e-2)


def test_bus_overload():
Expand Down
Loading