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..43e764e 100644 --- a/tests/test_geom.py +++ b/tests/test_geom.py @@ -2,7 +2,6 @@ import os from yapcad.geom import * from yapcad.geom_util import * -from yapcad.pyglet_drawable import * ## unit tests for yapCAD geom.py @@ -476,6 +475,7 @@ def test_visual_intersect(self): """Visual test of intersection calculation - requires display""" if not VISUALTEST: pytest.skip("Visual tests disabled (set VISUALTEST=true to enable)") + from yapcad.pyglet_drawable import * dd = pygletDraw() dd.linecolor='silver' # make a polyline spiral diff --git a/tests/test_geom3d.py b/tests/test_geom3d.py index 43c30f9..58e3344 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 * 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..8d12059 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 * @@ -11,6 +10,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 * + class TestSample: """test sampling-related operations""" diff --git a/tests/test_geometry.py b/tests/test_geometry.py index d7a1340..56c9df8 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -5,13 +5,13 @@ 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 * class TestGeometry: """Tests for the Geometry class""" diff --git a/tests/test_mesh_view.py b/tests/test_mesh_view.py index cfa0af0..e608e5a 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 * 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..dc58289 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 * def three2two(x): """take a 3D bounding box with non-zero z coordinates, return