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/2048.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow logos linux 26 1
6 changes: 4 additions & 2 deletions src/ansys/geometry/core/tools/prepare_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ def find_logos(
"""
from ansys.geometry.core.designer.body import Body

if BackendType.is_linux_service(self._grpc_client.backend_type):
# not yet available in Linux
if BackendType.is_linux_service(
self._grpc_client.backend_type
) and self._grpc_client.backend_version < (26, 1, 0):
# not yet available on Linux until 26.1.0
LOG.warning("Logo detection not available on Linux")
return

Expand Down
51 changes: 30 additions & 21 deletions tests/integration/test_prepare_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ def test_enhanced_share_topology(modeler: Modeler):

def test_detect_logos(modeler: Modeler):
"""Test logos are detected and deleted."""
if BackendType.is_linux_service(modeler.client.backend_type):
# not yet available in Linux
return
design = modeler.open_file(FILES_DIR / "partWithLogos.scdocx")
component = [c for c in design.components if c.name == "Default"][0]
body = [b for b in component.bodies if b.name == "Solid3"][0]
assert len(body.faces) == 189
result = modeler.prepare_tools.find_logos()
# no logos should be found is max height is not given
# no logos should be found if max height is not given
assert len(result.face_ids) == 0
result = modeler.prepare_tools.find_logos(max_height=0.005)
assert len(result.face_ids) == 147
success = modeler.prepare_tools.find_and_remove_logos(max_height=0.005)
# Skip the rest of the test if running on a Linux service backend
if BackendType.is_linux_service(modeler.client.backend_type):
return
assert success is True
assert len(body.faces) == 42
Comment on lines +139 to 143
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why had the rest to be skipped?

result = modeler.prepare_tools.find_and_remove_logos(None, min_height=0.001, max_height=0.005)
Expand All @@ -151,25 +151,34 @@ def test_detect_logos(modeler: Modeler):

def test_detect_and_fix_logo_as_problem_area(modeler: Modeler):
"""Test logos are detected and deleted as problem area"""
if BackendType.is_linux_service(modeler.client.backend_type):
# not yet available in Linux
return
design = modeler.open_file(FILES_DIR / "partWithLogos.scdocx")
# Get the component named "Default"
component = [c for c in design.components if c.name == "Default"][0]
# test that no issue occurs when no logos are found on body named Solid1
bodies = [b for b in component.bodies if b.name == "Solid1"]
result = modeler.prepare_tools.find_logos(bodies, max_height=0.005)
assert len(result.face_ids) == 0
success = result.fix()
assert success is False
# Remove logos from body named Solid3
bodies = [b for b in component.bodies if b.name == "Solid3"]
result = modeler.prepare_tools.find_logos(bodies, max_height=0.005)
assert len(result.face_ids) == 147
result.fix()
assert success is False
assert len(design.components[0].bodies[2].faces) == 42
body = [b for b in component.bodies if b.name == "Solid3"][0]
# Initial face count
assert len(body.faces) == 189
# Test finding logos without max height
result_no_max_height = modeler.prepare_tools.find_logos()
assert len(result_no_max_height.face_ids) == 0
# Test finding logos with max height
result_with_max_height = modeler.prepare_tools.find_logos(max_height=0.005)
assert len(result_with_max_height.face_ids) == 147
# Skip fix-related assertions if running on a Linux service backend
if BackendType.is_linux_service(modeler.client.backend_type):
return
# Test removing logos with max height
success_remove_logos = modeler.prepare_tools.find_and_remove_logos(max_height=0.005)
assert success_remove_logos is True
assert len(body.faces) == 42
# Test removing logos with min and max height (no logos should be removed)
result_min_max_height = modeler.prepare_tools.find_and_remove_logos(
None, min_height=0.001, max_height=0.005
)
assert result_min_max_height is False
# Test removing logos from specific bodies (no logos should be removed)
result_specific_bodies = modeler.prepare_tools.find_and_remove_logos(
design.components[0].bodies, min_height=0.001, max_height=0.005
)
assert result_specific_bodies is False


def test_volume_extract_bad_faces(modeler: Modeler):
Expand Down
59 changes: 58 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os

from beartype.roar import BeartypeCallHintParamViolation
import grpc
import numpy as np
from pint import Quantity
import pytest

from ansys.geometry.core.connection.backend import ApiVersions
from ansys.geometry.core.connection.backend import ApiVersions, BackendType
from ansys.geometry.core.connection.client import GrpcClient, wait_until_healthy
from ansys.geometry.core.connection.conversions import (
frame_to_grpc_frame,
Expand All @@ -40,6 +42,10 @@
sketch_segment_to_grpc_line,
unit_vector_to_grpc_direction,
)
from ansys.geometry.core.connection.product_instance import (
ProductInstance,
prepare_and_start_backend,
)
from ansys.geometry.core.math import Frame, Plane, Point2D, Point3D, UnitVector3D
from ansys.geometry.core.misc import UNITS, Angle
from ansys.geometry.core.sketch import Arc, Polygon, SketchCircle, SketchEllipse, SketchSegment
Expand Down Expand Up @@ -360,3 +366,54 @@ def test_api_versions_reader():

with pytest.raises(ValueError, match="0 is not a valid ApiVersions"): # Invalid version number
ApiVersions.parse_input(0)


def test_product_instance_initialization():
"""Test the initialization of the ProductInstance class."""
pid = -1234 # Example process ID
product_instance = ProductInstance(pid)
# Assert that the _pid attribute is correctly set
assert product_instance._pid == pid
assert product_instance.close() is False


def test_prepare_and_start_backend_conflicting_versions():
"""Test that providing both 'product_version' and 'version' raises a ValueError."""
with pytest.raises(
ValueError,
match="Both 'product_version' and 'version' arguments are provided."
" Please use only 'version'.",
):
prepare_and_start_backend(
backend_type=BackendType.WINDOWS_SERVICE, version=1900, product_version=1901
)


@pytest.mark.skipif(
os.name != "nt",
reason="Test skipped on Linux because it is specific to Windows backends.",
)
def test_prepare_and_start_backend_unavailable_version():
"""Test that an unavailable product version raises a SystemError."""
with pytest.raises(
SystemError,
match="The requested Ansys product's version 1901 is not available,"
" please specify a different version.",
):
prepare_and_start_backend(backend_type=BackendType.WINDOWS_SERVICE, product_version=1901)


@pytest.mark.skipif(
os.name != "nt",
reason="Test skipped on Linux because it is specific to Windows backends.",
)
def test_prepare_and_start_backend_invalid_version():
"""Test that a non-integer 'version' raises a ValueError."""
with pytest.raises(
ValueError,
match="The 'version' argument must be an integer representing the product version.",
):
prepare_and_start_backend(
backend_type=BackendType.WINDOWS_SERVICE,
version="invalid_version", # Pass a non-integer value for version
)
Loading