Skip to content

Commit

Permalink
CI: Test fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 16, 2024
1 parent 1095207 commit a0dd079
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: QA

on:
pull_request:
push:
branches:
- main

jobs:
test:
name: linting & spelling
runs-on: ubuntu-latest
env:
TERM: xterm-256color

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python '3,11'
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install Dependencies
run: |
make dev-deps
- name: Run Quality Assurance
run: |
make qa
- name: Run Code Checks
run: |
make check
- name: Run Bash Code Checks
run: |
make shellcheck
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests

on:
pull_request:
push:
branches:
- main

jobs:
test:
name: Python ${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.9', '3.10', '3.11']

steps:
- name: Checkout Code
uses: actions/checkout@v3

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

- name: Install Dependencies
run: |
make dev-deps
- name: Run Tests
run: |
make pytest
- name: Coverage
if: ${{ matrix.python == '3.9' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m pip install coveralls
coveralls --service=github
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
build/
_build/
*.o
*.so
*.a
*.py[cod]
*.egg-info
dist/
__pycache__
.DS_Store
*.deb
*.dsc
*.build
*.changes
*.orig.*
packaging/*tar.xz
library/debian/
.coverage
.pytest_cache
.tox
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: usage check pytest qa build-deps check
usage:
@echo "Usage: make <target>, where target is one of:\n"
@echo "dev-deps: install Python dev dependencies"
@echo "check: perform basic integrity checks on the codebase"
@echo "shellcheck: perform check on shell scripts"
@echo "qa: run linting and package QA"
@echo "pytest: run Python test fixtures"

dev-deps:
python3 -m pip install -r requirements-dev.txt
sudo apt install dos2unix shellcheck

check:
@bash check.sh

shellcheck:
shellcheck *.sh

qa:
tox -e qa

pytest:
tox -e py
34 changes: 34 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# This script handles some basic QA checks on the source

TERM=${TERM:="xterm-256color"}

success() {
echo -e "$(tput setaf 2)$1$(tput sgr0)"
}

inform() {
echo -e "$(tput setaf 6)$1$(tput sgr0)"
}

warning() {
echo -e "$(tput setaf 1)$1$(tput sgr0)"
}
inform "Checking for trailing whitespace..."
if grep -IUrn --color "[[:blank:]]$" --exclude-dir=dist --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO; then
warning "Trailing whitespace found!"
exit 1
else
success "No trailing whitespace found."
fi
printf "\n"

inform "Checking for DOS line-endings..."
if grep -lIUrn --color $'\r' --exclude-dir=dist --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile; then
warning "DOS line-endings found!"
exit 1
else
success "No DOS line-endings found."
fi
printf "\n"
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
check-manifest
ruff
codespell
isort
tox
39 changes: 39 additions & 0 deletions tests/test_validate_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import glob
import json

import pytest


def validate_alt_mode(data):
# name = data["name"]
mode_type = data.get("type", "")

assert mode_type != ""
assert not mode_type.endswith("?")


def validate_pin(data):
alt_modes = data.get("alt_modes", [])

for alt_mode in alt_modes:
validate_alt_mode(alt_mode)


def validate_header(data):
width = data["width"]
height = data["height"]
# orientation = data["orientation"]
pins = data["pins"]

assert width * height == len(pins)

for pin in pins:
validate_pin(pin)


@pytest.mark.parametrize('board_file', glob.glob("boards/*.json"))
def test_validate_board_json_files(board_file):
data = json.load(open(board_file, "r"))

for name, header in data["headers"].items():
validate_header(header)
25 changes: 25 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tox]
envlist = py,qa
skip_missing_interpreters = True
isolated_build = true
minversion = 4.0.0

[testenv]
commands =
coverage run -m pytest -v -r wsx
coverage report
deps =
mock
pytest>=3.1
pytest-cov
build

[testenv:qa]
commands =
isort --check .
ruff check .
codespell .
deps =
ruff
codespell
isort

0 comments on commit a0dd079

Please sign in to comment.