diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..64cd658 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,42 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install OpenGL (GLU) + run: sudo apt-get update && sudo apt-get install -y libglu1-mesa libglu1-mesa-dev + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + VISUALTEST=false PYTHONPATH=${PWD}/src:$PYTHONPATH pytest tests/ -m "not visual" diff --git a/tests/test_geom.py b/tests/test_geom.py index 2b96361..4d19e9c 100644 --- a/tests/test_geom.py +++ b/tests/test_geom.py @@ -2,12 +2,13 @@ import os from yapcad.geom import * from yapcad.geom_util import * -from yapcad.pyglet_drawable import * ## unit tests for yapCAD geom.py # Control flag for visual tests - set via environment variable or directly VISUALTEST = os.environ.get('VISUALTEST', 'false').lower() in ('true', '1', 'yes') +if VISUALTEST: + from yapcad.pyglet_drawable import pygletDraw class TestPoint: """unit tests for yapCAD point functions""" diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 43c30f9..c52ad97 100644 --- a/tests/test_geom3d.py +++ b/tests/test_geom3d.py @@ -5,12 +5,13 @@ from yapcad.geom_util import * from yapcad.geom3d import * from yapcad.geom3d_util import * -from yapcad.pyglet_drawable import * from yapcad.poly import * from yapcad.combine import * # Control flag for visual tests - set via environment variable or directly VISUALTEST = os.environ.get('VISUALTEST', 'false').lower() in ('true', '1', 'yes') +if VISUALTEST: + from yapcad.pyglet_drawable import pygletDraw def randomPoints(bbox,numpoints): """Given a 3D bounding box and a number of points to generate, diff --git a/tests/test_geom_util.py b/tests/test_geom_util.py index 024dff4..d95c0e0 100644 --- a/tests/test_geom_util.py +++ b/tests/test_geom_util.py @@ -2,7 +2,6 @@ import os from yapcad.geom import * from yapcad.geom_util import * -from yapcad.pyglet_drawable import * from yapcad.poly import * from yapcad.combine import * @@ -10,7 +9,9 @@ # Control flag for visual tests - set via environment variable or directly VISUALTEST = os.environ.get('VISUALTEST', 'false').lower() in ('true', '1', 'yes') - +if VISUALTEST: + from yapcad.pyglet_drawable import pygletDraw + class TestSample: """test sampling-related operations""" diff --git a/tests/test_geometry.py b/tests/test_geometry.py index d7a1340..2921875 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -1,17 +1,16 @@ import pytest import os import random -from yapcad.pyglet_drawable import * from yapcad.geom import * from yapcad.geom_util import * from yapcad.geometry import * -from yapcad.pyglet_drawable import * """test functions for the yapcad.geometry module""" # Control flag for visual tests - set via environment variable or directly VISUALTEST = os.environ.get('VISUALTEST', 'false').lower() in ('true', '1', 'yes') - +if VISUALTEST: + from yapcad.pyglet_drawable import pygletDraw class TestGeometry: """Tests for the Geometry class""" diff --git a/tests/test_mesh_view.py b/tests/test_mesh_view.py index cfa0af0..3f6e5cc 100644 --- a/tests/test_mesh_view.py +++ b/tests/test_mesh_view.py @@ -7,12 +7,11 @@ from yapcad.geom3d_util import conic, sphere from yapcad.geom_util import geomlist2poly, geomlist2poly_components from yapcad.mesh import mesh_view -from yapcad.pyglet_drawable import pygletDraw from yapcad.poly import Polygon, Rect - VISUALTEST = os.environ.get('VISUALTEST', 'false').lower() in ('true', '1', 'yes') - +if VISUALTEST: + from yapcad.pyglet_drawable import pygletDraw def _strip_w(pt): return tuple(round(coord, 6) for coord in pt[:3]) diff --git a/tests/test_octtree.py b/tests/test_octtree.py index 1393f7b..667c156 100644 --- a/tests/test_octtree.py +++ b/tests/test_octtree.py @@ -3,10 +3,11 @@ import random from yapcad.geom import * from yapcad.octtree import * -from yapcad.pyglet_drawable import * # Control flag for visual tests - set via environment variable or directly VISUALTEST = os.environ.get('VISUALTEST', 'false').lower() in ('true', '1', 'yes') +if VISUALTEST: + from yapcad.pyglet_drawable import pygletDraw def three2two(x): """take a 3D bounding box with non-zero z coordinates, return