Skip to content

Commit faa5c93

Browse files
RyanJWardpre-commit-ci[bot]pyansys-ci-bot
authored
feat: allow logos Linux 26 1 (#2048)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
1 parent a7a2265 commit faa5c93

File tree

4 files changed

+93
-24
lines changed

4 files changed

+93
-24
lines changed

doc/changelog.d/2048.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow logos linux 26 1

src/ansys/geometry/core/tools/prepare_tools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,10 @@ def find_logos(
320320
"""
321321
from ansys.geometry.core.designer.body import Body
322322

323-
if BackendType.is_linux_service(self._grpc_client.backend_type):
324-
# not yet available in Linux
323+
if BackendType.is_linux_service(
324+
self._grpc_client.backend_type
325+
) and self._grpc_client.backend_version < (26, 1, 0):
326+
# not yet available on Linux until 26.1.0
325327
LOG.warning("Logo detection not available on Linux")
326328
return
327329

tests/integration/test_prepare_tools.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ def test_enhanced_share_topology(modeler: Modeler):
126126

127127
def test_detect_logos(modeler: Modeler):
128128
"""Test logos are detected and deleted."""
129-
if BackendType.is_linux_service(modeler.client.backend_type):
130-
# not yet available in Linux
131-
return
132129
design = modeler.open_file(FILES_DIR / "partWithLogos.scdocx")
133130
component = [c for c in design.components if c.name == "Default"][0]
134131
body = [b for b in component.bodies if b.name == "Solid3"][0]
135132
assert len(body.faces) == 189
136133
result = modeler.prepare_tools.find_logos()
137-
# no logos should be found is max height is not given
134+
# no logos should be found if max height is not given
138135
assert len(result.face_ids) == 0
139136
result = modeler.prepare_tools.find_logos(max_height=0.005)
140137
assert len(result.face_ids) == 147
141138
success = modeler.prepare_tools.find_and_remove_logos(max_height=0.005)
139+
# Skip the rest of the test if running on a Linux service backend
140+
if BackendType.is_linux_service(modeler.client.backend_type):
141+
return
142142
assert success is True
143143
assert len(body.faces) == 42
144144
result = modeler.prepare_tools.find_and_remove_logos(None, min_height=0.001, max_height=0.005)
@@ -151,25 +151,34 @@ def test_detect_logos(modeler: Modeler):
151151

152152
def test_detect_and_fix_logo_as_problem_area(modeler: Modeler):
153153
"""Test logos are detected and deleted as problem area"""
154-
if BackendType.is_linux_service(modeler.client.backend_type):
155-
# not yet available in Linux
156-
return
157154
design = modeler.open_file(FILES_DIR / "partWithLogos.scdocx")
158-
# Get the component named "Default"
159155
component = [c for c in design.components if c.name == "Default"][0]
160-
# test that no issue occurs when no logos are found on body named Solid1
161-
bodies = [b for b in component.bodies if b.name == "Solid1"]
162-
result = modeler.prepare_tools.find_logos(bodies, max_height=0.005)
163-
assert len(result.face_ids) == 0
164-
success = result.fix()
165-
assert success is False
166-
# Remove logos from body named Solid3
167-
bodies = [b for b in component.bodies if b.name == "Solid3"]
168-
result = modeler.prepare_tools.find_logos(bodies, max_height=0.005)
169-
assert len(result.face_ids) == 147
170-
result.fix()
171-
assert success is False
172-
assert len(design.components[0].bodies[2].faces) == 42
156+
body = [b for b in component.bodies if b.name == "Solid3"][0]
157+
# Initial face count
158+
assert len(body.faces) == 189
159+
# Test finding logos without max height
160+
result_no_max_height = modeler.prepare_tools.find_logos()
161+
assert len(result_no_max_height.face_ids) == 0
162+
# Test finding logos with max height
163+
result_with_max_height = modeler.prepare_tools.find_logos(max_height=0.005)
164+
assert len(result_with_max_height.face_ids) == 147
165+
# Skip fix-related assertions if running on a Linux service backend
166+
if BackendType.is_linux_service(modeler.client.backend_type):
167+
return
168+
# Test removing logos with max height
169+
success_remove_logos = modeler.prepare_tools.find_and_remove_logos(max_height=0.005)
170+
assert success_remove_logos is True
171+
assert len(body.faces) == 42
172+
# Test removing logos with min and max height (no logos should be removed)
173+
result_min_max_height = modeler.prepare_tools.find_and_remove_logos(
174+
None, min_height=0.001, max_height=0.005
175+
)
176+
assert result_min_max_height is False
177+
# Test removing logos from specific bodies (no logos should be removed)
178+
result_specific_bodies = modeler.prepare_tools.find_and_remove_logos(
179+
design.components[0].bodies, min_height=0.001, max_height=0.005
180+
)
181+
assert result_specific_bodies is False
173182

174183

175184
def test_volume_extract_bad_faces(modeler: Modeler):

tests/test_connection.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23+
import os
24+
2325
from beartype.roar import BeartypeCallHintParamViolation
2426
import grpc
2527
import numpy as np
2628
from pint import Quantity
2729
import pytest
2830

29-
from ansys.geometry.core.connection.backend import ApiVersions
31+
from ansys.geometry.core.connection.backend import ApiVersions, BackendType
3032
from ansys.geometry.core.connection.client import GrpcClient, wait_until_healthy
3133
from ansys.geometry.core.connection.conversions import (
3234
frame_to_grpc_frame,
@@ -40,6 +42,10 @@
4042
sketch_segment_to_grpc_line,
4143
unit_vector_to_grpc_direction,
4244
)
45+
from ansys.geometry.core.connection.product_instance import (
46+
ProductInstance,
47+
prepare_and_start_backend,
48+
)
4349
from ansys.geometry.core.math import Frame, Plane, Point2D, Point3D, UnitVector3D
4450
from ansys.geometry.core.misc import UNITS, Angle
4551
from ansys.geometry.core.sketch import Arc, Polygon, SketchCircle, SketchEllipse, SketchSegment
@@ -360,3 +366,54 @@ def test_api_versions_reader():
360366

361367
with pytest.raises(ValueError, match="0 is not a valid ApiVersions"): # Invalid version number
362368
ApiVersions.parse_input(0)
369+
370+
371+
def test_product_instance_initialization():
372+
"""Test the initialization of the ProductInstance class."""
373+
pid = -1234 # Example process ID
374+
product_instance = ProductInstance(pid)
375+
# Assert that the _pid attribute is correctly set
376+
assert product_instance._pid == pid
377+
assert product_instance.close() is False
378+
379+
380+
def test_prepare_and_start_backend_conflicting_versions():
381+
"""Test that providing both 'product_version' and 'version' raises a ValueError."""
382+
with pytest.raises(
383+
ValueError,
384+
match="Both 'product_version' and 'version' arguments are provided."
385+
" Please use only 'version'.",
386+
):
387+
prepare_and_start_backend(
388+
backend_type=BackendType.WINDOWS_SERVICE, version=1900, product_version=1901
389+
)
390+
391+
392+
@pytest.mark.skipif(
393+
os.name != "nt",
394+
reason="Test skipped on Linux because it is specific to Windows backends.",
395+
)
396+
def test_prepare_and_start_backend_unavailable_version():
397+
"""Test that an unavailable product version raises a SystemError."""
398+
with pytest.raises(
399+
SystemError,
400+
match="The requested Ansys product's version 1901 is not available,"
401+
" please specify a different version.",
402+
):
403+
prepare_and_start_backend(backend_type=BackendType.WINDOWS_SERVICE, product_version=1901)
404+
405+
406+
@pytest.mark.skipif(
407+
os.name != "nt",
408+
reason="Test skipped on Linux because it is specific to Windows backends.",
409+
)
410+
def test_prepare_and_start_backend_invalid_version():
411+
"""Test that a non-integer 'version' raises a ValueError."""
412+
with pytest.raises(
413+
ValueError,
414+
match="The 'version' argument must be an integer representing the product version.",
415+
):
416+
prepare_and_start_backend(
417+
backend_type=BackendType.WINDOWS_SERVICE,
418+
version="invalid_version", # Pass a non-integer value for version
419+
)

0 commit comments

Comments
 (0)