mirror of
https://github.com/johndoe6345789/bamboogenerator.git
synced 2026-04-24 13:24:54 +00:00
Add unit tests and GitHub Action
This commit is contained in:
20
.github/workflows/python-tests.yml
vendored
Normal file
20
.github/workflows/python-tests.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Python unit tests
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install pytest trimesh shapely
|
||||
- name: Run tests
|
||||
env:
|
||||
PYTHONPATH: ${{ github.workspace }}
|
||||
run: pytest -vv
|
||||
13
tests/test_export.py
Normal file
13
tests/test_export.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
import pytest
|
||||
import trimesh
|
||||
from parametric_cad.primitives.box import Box
|
||||
from parametric_cad.export.stl import STLExporter
|
||||
|
||||
|
||||
def test_stl_exporter(tmp_path):
|
||||
exporter = STLExporter(output_dir=tmp_path)
|
||||
box = Box(1.0, 1.0, 1.0)
|
||||
path = exporter.export_mesh(box, "test_box", preview=False)
|
||||
assert os.path.isfile(path)
|
||||
assert path == str(tmp_path / "test_box.stl")
|
||||
15
tests/test_mechanisms.py
Normal file
15
tests/test_mechanisms.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
import trimesh
|
||||
|
||||
from parametric_cad.mechanisms.butthinge import ButtHinge
|
||||
|
||||
|
||||
def test_butthinge_mesh_and_translation():
|
||||
hinge = ButtHinge()
|
||||
mesh = hinge.mesh()
|
||||
assert isinstance(mesh, trimesh.Trimesh)
|
||||
original_centroid = mesh.centroid.copy()
|
||||
hinge.at(1.0, 2.0, 3.0)
|
||||
translated_centroid = hinge.mesh().centroid
|
||||
assert np.allclose(translated_centroid, original_centroid + [1.0, 2.0, 3.0])
|
||||
23
tests/test_primitives.py
Normal file
23
tests/test_primitives.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
import trimesh
|
||||
from math import cos, pi
|
||||
|
||||
from parametric_cad.primitives.box import Box
|
||||
from parametric_cad.primitives.gear import SpurGear
|
||||
|
||||
|
||||
def test_box_mesh_extents_and_position():
|
||||
box = Box(1.0, 2.0, 3.0).at(1.0, 1.0, 1.0)
|
||||
mesh = box.mesh()
|
||||
assert np.allclose(mesh.centroid, [1.0, 1.0, 1.0])
|
||||
assert mesh.extents[0] == pytest.approx(1.0)
|
||||
assert mesh.extents[1] == pytest.approx(2.0)
|
||||
assert mesh.extents[2] == pytest.approx(3.0)
|
||||
|
||||
|
||||
def test_spur_gear_diameters():
|
||||
gear = SpurGear(module=2.0, teeth=10)
|
||||
assert gear.pitch_diameter == pytest.approx(20.0)
|
||||
expected_base = gear.pitch_diameter * cos(20 * pi / 180)
|
||||
assert gear.base_diameter == pytest.approx(expected_base)
|
||||
Reference in New Issue
Block a user