-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests * add workflow * fix workflow
- Loading branch information
Showing
10 changed files
with
266 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Build and Test | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- "*" | ||
|
||
schedule: | ||
- cron: "0 0 * * 0" | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: ["ubuntu-latest", "macos-latest", "windows-latest"] | ||
python-version: ["3.10", "3.11"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: "pip" | ||
|
||
- name: Install | ||
run: | | ||
pip install uv | ||
uv pip install --system blender_tpms@. bpy pytest | ||
- name: Test | ||
run: pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__pycache__ | ||
__pycache__ | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pyvista as pv | ||
from blender_tpms.interface import get_all_surfaces, polydata_to_mesh | ||
|
||
# ruff: noqa: S101 | ||
|
||
|
||
def test_polydata_to_mesh() -> None: | ||
"""Test polydata_to_mesh function.""" | ||
polydata = pv.Cube() | ||
mesh = polydata_to_mesh(polydata, mesh_name="Box") | ||
assert mesh.name == "Box" | ||
assert len(mesh.vertices) == 8 | ||
assert len(mesh.polygons) == 12 | ||
|
||
|
||
def test_get_all_surfaces() -> None: | ||
"""Test get_all_surfaces function.""" | ||
surfaces = get_all_surfaces() | ||
assert len(surfaces) == 30 | ||
for surface in surfaces: | ||
assert len(surface) == 3 | ||
assert isinstance(surface[0], str) | ||
assert isinstance(surface[1], str) | ||
assert isinstance(surface[2], str) | ||
assert surface[0] == surface[1] == surface[2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import blender_tpms.tpms | ||
import bpy | ||
from blender_tpms.interface import polydata_to_mesh | ||
from blender_tpms.ui import apply_material, set_shade_auto_smooth | ||
|
||
|
||
def test_auto_smooth() -> None: | ||
tpms = blender_tpms.tpms.Tpms() | ||
mesh = polydata_to_mesh(tpms.sheet, mesh_name="Tpms") | ||
|
||
obj = bpy.data.objects.new(mesh.name, mesh) | ||
bpy.context.collection.objects.link(obj) | ||
bpy.context.view_layer.objects.active = obj | ||
obj.select_set(state=True) | ||
|
||
assert mesh.name == "Tpms" | ||
set_shade_auto_smooth() | ||
|
||
|
||
def test_apply_material() -> None: | ||
tpms = blender_tpms.tpms.Tpms() | ||
mesh = polydata_to_mesh(tpms.sheet, mesh_name="Tpms") | ||
|
||
obj = bpy.data.objects.new(mesh.name, mesh) | ||
bpy.context.collection.objects.link(obj) | ||
bpy.context.view_layer.objects.active = obj | ||
obj.select_set(state=True) | ||
|
||
apply_material( | ||
mesh=mesh, | ||
tpms=tpms, | ||
attr_name="surface", | ||
colormap="coolwarm", | ||
n_colors=9, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from inspect import getmembers, isfunction | ||
from typing import Callable | ||
|
||
import numpy as np | ||
import pytest | ||
from blender_tpms.tpms import surfaces | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"surface_function", | ||
[func[1] for func in getmembers(surfaces, isfunction)], | ||
) | ||
def test_surfaces(surface_function: Callable) -> None: | ||
"""Test all TPMS surfaces.""" | ||
assert -np.inf < surface_function(0, 0, 0) < np.inf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from blender_tpms.tpms import CylindricalTpms, SphericalTpms, Tpms | ||
|
||
|
||
def test_tpms() -> None: | ||
tpms = Tpms() | ||
assert tpms is not None | ||
assert tpms.surface is not None | ||
assert tpms.sheet is not None | ||
assert tpms.lower_skeletal is not None | ||
assert tpms.upper_skeletal is not None | ||
assert tpms.skeletals is not None | ||
assert tpms.relative_density > 0 | ||
assert tpms.vtk_sheet() is not None | ||
assert tpms.vtk_lower_skeletal() is not None | ||
assert tpms.vtk_upper_skeletal() is not None | ||
|
||
|
||
def test_cylindrical_tpms() -> None: | ||
tpms = CylindricalTpms() | ||
|
||
assert tpms.relative_density > 0 | ||
|
||
|
||
def test_spherical_tpms() -> None: | ||
tpms = SphericalTpms() | ||
|
||
assert tpms.relative_density > 0 |