Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2070.test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding test coverage for designer, sketch, misc
11 changes: 11 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,14 @@ def use_service_colors():

# Code here runs after the test, reverting the state
pyansys_geometry.USE_SERVICE_COLORS = False


@pytest.fixture(scope="function")
def use_grpc_client_old_backend(modeler: Modeler):
currentbackend = modeler._grpc_client._backend_version
modeler._grpc_client._backend_version = (24, 2, 0)

yield # This allows the test to run

# Code here runs after the test, reverting the state
modeler._grpc_client._backend_version = currentbackend
Binary file not shown.
26 changes: 24 additions & 2 deletions tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""Test design interaction."""

import os
from pathlib import Path

import matplotlib.colors as mcolors
import numpy as np
Expand All @@ -40,7 +41,7 @@
from ansys.geometry.core.designer.body import CollisionType, FillStyle, MasterBody
from ansys.geometry.core.designer.face import FaceLoopType
from ansys.geometry.core.designer.part import MasterComponent, Part
from ansys.geometry.core.errors import GeometryExitedError
from ansys.geometry.core.errors import GeometryExitedError, GeometryRuntimeError
from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType
from ansys.geometry.core.math import (
IDENTITY_MATRIX44,
Expand All @@ -54,7 +55,7 @@
UnitVector3D,
Vector3D,
)
from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Accuracy, Angle, Distance
from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Accuracy, Angle, Distance, checks
from ansys.geometry.core.misc.auxiliary import DEFAULT_COLOR
from ansys.geometry.core.parameters.parameter import ParameterType, ParameterUpdateStatus
from ansys.geometry.core.shapes import (
Expand All @@ -77,6 +78,20 @@
from .conftest import FILES_DIR


def test_design_is_close(modeler: Modeler):
# Testing to see if design is closed and whether more operations can be performed on it
sketch = Sketch()
sketch.box(Point2D([0, 0]), 10, 10)
design = modeler.create_design("Box")
design.extrude_sketch("Box", sketch, 2)
design.close()
with pytest.raises(
GeometryRuntimeError,
match="The design has been closed on the backend. Cannot perform any operations on it.",
):
checks.ensure_design_is_active(design.bodies[0].edges)


def test_design_selection(modeler: Modeler):
"""Test to validate the designer selection for edges and __repr__ method."""
sketch = Sketch()
Expand Down Expand Up @@ -490,6 +505,13 @@ def test_named_selections(modeler: Modeler):
assert len(design.named_selections) == 3


def test_old_backend_version(modeler: Modeler, use_grpc_client_old_backend: Modeler):
# Try to vefify name selection using earlier backend version
design = modeler.open_file(Path(FILES_DIR, "25R1BasicBoxNameSelection.scdocx"))
hello = design.named_selections
assert hello[0].faces == []


def test_empty_named_selection(modeler: Modeler):
"""Test for verifying the creation of an empty ``NamedSelection``."""
# Create your design on the server side
Expand Down
40 changes: 40 additions & 0 deletions tests/test_misc_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from ansys.geometry.core.math import Point3D
from ansys.geometry.core.misc import (
UNITS,
TessellationOptions,
auxiliary,
check_is_float_int,
check_ndarray_is_float_int,
check_ndarray_is_non_zero,
Expand All @@ -42,6 +44,44 @@
)


def test_tessellation_options():
# Testing tessellation options
tessellation_options = TessellationOptions(
surface_deviation=0.01,
angle_deviation=0.1,
max_aspect_ratio=2.0,
max_edge_length=5.0,
watertight=True,
)
assert tessellation_options.surface_deviation == 0.01
assert tessellation_options.angle_deviation == 0.1
assert tessellation_options.max_aspect_ratio == 2.0
assert tessellation_options.max_edge_length == 5.0
assert tessellation_options.watertight is True


def test_misc_checks():
# Testing backend_version_decorator for log warning
@min_backend_version(25, 2, 0)
def fake_temp_operation(obj):
print("Performing operation...")

invalid_object = {"key": "value"}
fake_temp_operation(invalid_object)


def test_check_auxiliary():
"""Test the auxiliary functions for checking color conversion."""
with pytest.raises(ValueError, match="RGB values in the 0-1 range must be floats."):
auxiliary.convert_color_to_hex(tuple([0, 1, 0]))
with pytest.raises(ValueError, match="RGB values in the 0-255 range must be integers."):
auxiliary.convert_color_to_hex(tuple([1.1, 1.1, 1.1, 1.1]))
with pytest.raises(ValueError, match="RGB tuple contains mixed ranges or invalid values."):
auxiliary.convert_color_to_hex(tuple([256, 11, 1.1]))
with pytest.raises(ValueError, match="Invalid color value:."):
auxiliary.convert_color_to_hex((125, 128))


def test_check_type():
"""Test that the __eq__ check is working properly.

Expand Down
8 changes: 7 additions & 1 deletion tests/test_misc_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
from pint import Quantity
import pytest

from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Angle, Distance
from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Angle, Distance, measurements


def test_repr_():
# Testing the __repr__ method of the Measurement class
mea = measurements.Measurement(5.0, DEFAULT_UNITS.LENGTH, DEFAULT_UNITS.LENGTH)
assert measurements.Measurement.__repr__(mea) == "5.0 meter"


def test_distance():
Expand Down
18 changes: 17 additions & 1 deletion tests/test_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
SketchCircle,
SketchEdge,
SketchEllipse,
SketchFace,
SketchSegment,
Slot,
SpurGear,
Expand Down Expand Up @@ -122,8 +123,11 @@ def test_sketch_circle_plane_change():
assert circle.dir_z == Vector3D([0, -1, 0])


@pytest.mark.skipif(
not are_graphics_available(), reason="Skipping due to graphics requirements missing"
)
def test_sketch_face():
"""Test the sketch face perimeter and change plane functionality"""
"""Test the sketch face perimeter, change plane, and visualization polydata functionality"""
sketch = Sketch()
per = Triangle(Point2D([10, 10]), Point2D([2, 1]), Point2D([10, -10])).perimeter
assert abs((per - 45.64306508752774 * UNITS.m).m) <= 5e-14
Expand All @@ -134,6 +138,18 @@ def test_sketch_face():
)
sketch.faces[0].plane_change(new_plane)

start_point = Point2D([0, 0], unit=UNITS.meter)
end_point = Point2D([5, 5], unit=UNITS.kilometer)
segment1 = SketchSegment(start_point, end_point)
sketch1 = SketchFace()
sketch1._edges = [segment1]
polyda = sketch1.visualization_polydata
assert polyda.center == pytest.approx(
([2500.0, 2500.0, 0.0]),
rel=1e-7,
abs=1e-8,
)


def test_sketch_edge():
"""Test the sketch edge functionality"""
Expand Down
Loading