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

Add GitHub Python workflow tests #2

Merged
merged 16 commits into from
Mar 31, 2024
Merged
43 changes: 43 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Python checks

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.11"]
clang: ["18"]

steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Setup Clang
uses: egor-tensin/setup-clang@v1
with:
version: ${{ matrix.clang }}
platform: x64
- name: Install virtual env and dependencies
run: |
python -m venv .venv
source ./.venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Type checks
run: |
source ./.venv/bin/activate
python -m mypy *.py --check-untyped-defs
- name: Tests
run: |
source ./.venv/bin/activate
PY_CPPMODEL_LIBCLANG_PATH=/usr/lib/llvm-18/lib/libclang-18.so.1 \
python -m unittest discover --verbose .
12 changes: 12 additions & 0 deletions test.macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Virtual environment setup
python3 -m venv .venv # Create a Python virtual env
source ./.venv/bin/activate # Activate the virtual env for bash by source.

# Type checks
python -m mypy *.py --check-untyped-defs # Run mypy to check type hints

Unit tests
PY_CPPMODEL_LIBCLANG_PATH=/Library/Developer/CommandLineTools/usr/lib/libclang.dylib \
python -m unittest discover --verbose . # Run tests
10 changes: 0 additions & 10 deletions test.sh

This file was deleted.

9 changes: 8 additions & 1 deletion test_py_cppmodel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import clang
import os
import py_cppmodel
import unittest

clang.cindex.Config.set_library_path("/Library/Developer/CommandLineTools/usr/lib/") # type: ignore
from ctypes.util import find_library

LIBCLANG_PATH = os.environ.get("PY_CPPMODEL_LIBCLANG_PATH")
if not LIBCLANG_PATH:
raise RuntimeError("PY_CPPMODEL_LIBCLANG_PATH is unset")

clang.cindex.Config.set_library_file(LIBCLANG_PATH) # type: ignore

from clang.cindex import TranslationUnit

Expand Down
Loading