Skip to content

Commit f6c174e

Browse files
RyanJWardpyansys-ci-botpre-commit-ci[bot]
authored
test: bug fix test and round trip open file tests (#2107)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 15e0d51 commit f6c174e

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

doc/changelog.d/2107.test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bug fix test and round trip open file tests

tests/integration/test_design_export.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from ansys.geometry.core.math import Plane, Point2D, Point3D, UnitVector3D, Vector3D
3333
from ansys.geometry.core.sketch import Sketch
3434

35+
from ..conftest import are_graphics_available
3536
from .conftest import (
3637
FILES_DIR,
3738
skip_if_core_service,
@@ -408,3 +409,79 @@ def test_import_export_reimport_design_x_t(
408409
# Assertions to check the number of components and bodies
409410
assert len(design.components[0].bodies) == 1
410411
assert len(design.components[1].components[0].components[0].bodies) == 1
412+
413+
414+
@pytest.mark.skipif(
415+
not are_graphics_available(), reason="Skipping due to graphics requirements missing"
416+
)
417+
def test_import_export_glb(modeler: Modeler, tmp_path_factory: pytest.TempPathFactory):
418+
"""Test exporting a design to GLB format."""
419+
from ansys.geometry.core.plotting import GeometryPlotter
420+
421+
working_directory = tmp_path_factory.mktemp("test_import_export_glb")
422+
design = modeler.create_design("Assembly")
423+
design.add_component("Component_1")
424+
file = Path(FILES_DIR, "reactorWNS.scdocx")
425+
component = design.insert_file(file)
426+
# Check that the design has components
427+
assert len(design.components) == 2, "The design does not contain any components."
428+
429+
# Check that the imported component has bodies
430+
assert len(design.components[1].components[0].bodies) == 3, (
431+
"The imported component does not contain any bodies."
432+
)
433+
pl = GeometryPlotter()
434+
435+
output_glb_path = Path(working_directory, "plot_box_glb.glb")
436+
pl.export_glb(plotting_object=component, filename=output_glb_path)
437+
assert output_glb_path.exists(), f"GLB file {output_glb_path} does not exist."
438+
439+
# Check that the GLB file size is greater than 0 bytes
440+
assert output_glb_path.stat().st_size > 0, f"GLB file {output_glb_path} is empty."
441+
442+
443+
@pytest.mark.parametrize(
444+
"file_format, extension, original_file, expected_components, expected_bodies",
445+
[
446+
(DesignFileFormat.PARASOLID_TEXT, "x_t", "rci_std.x_t", 2, 1),
447+
(DesignFileFormat.SCDOCX, "scdocx", "reactorWNS.scdocx", 1, 3),
448+
],
449+
)
450+
def test_import_export_open_file_design(
451+
modeler: Modeler,
452+
tmp_path_factory: pytest.TempPathFactory,
453+
file_format,
454+
extension,
455+
original_file,
456+
expected_components,
457+
expected_bodies,
458+
):
459+
"""Test importing, exporting, and opening a file in a new design."""
460+
# Define the working directory and file paths
461+
working_directory = tmp_path_factory.mktemp("test_import_export_reimport")
462+
original_file_path = Path(FILES_DIR, original_file)
463+
reexported_file = Path(working_directory, f"reexported.{extension}")
464+
465+
# Create a new design
466+
design = modeler.create_design("Assembly")
467+
468+
# Import the original file
469+
design.insert_file(original_file_path)
470+
471+
# Export the design to a new file
472+
design.download(reexported_file, format=file_format)
473+
474+
# Ensure the re-exported file exists
475+
assert reexported_file.exists(), f"Re-exported file {reexported_file} does not exist."
476+
477+
# Re-import the exported file
478+
design = modeler.open_file(reexported_file)
479+
480+
# Assertions to check the number of components and bodies
481+
assert len(design.components) == expected_components, (
482+
f"Expected {expected_components} components, but found {len(design.components)}."
483+
)
484+
assert len(design.components[0].components[0].bodies) == expected_bodies, (
485+
f"Expected {expected_bodies} bodies, but found "
486+
f"{len(design.components[0].components[0].bodies)}."
487+
)

tests/test_shapes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def test_contains_value():
164164
def test_planar_surface():
165165
"""Test the planar surface functionality."""
166166
with pytest.raises(
167-
ValueError, match="Plane reference \(dir_x\) and axis \(dir_z\) must be perpendicular."
167+
ValueError,
168+
match=re.escape("Plane reference (dir_x) and axis (dir_z) must be perpendicular."),
168169
):
169170
PlaneSurface(Point3D([0, 0, 0]), UNITVECTOR3D_X, UNITVECTOR3D_X)
170171
plane0 = PlaneSurface(Point3D([0, 0, 0]), UNITVECTOR3D_X, UNITVECTOR3D_Y)

0 commit comments

Comments
 (0)