Skip to content

Commit 0c0a7d1

Browse files
test: internalize external documents (#2109)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent b9beb09 commit 0c0a7d1

File tree

10 files changed

+65
-6
lines changed

10 files changed

+65
-6
lines changed

doc/changelog.d/2109.test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Internalize external documents
21.3 KB
Binary file not shown.
21.4 KB
Binary file not shown.
21.3 KB
Binary file not shown.
19.5 KB
Binary file not shown.
19.5 KB
Binary file not shown.
25.6 KB
Binary file not shown.

tests/integration/test_design_import.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,3 +535,32 @@ def test_design_insert_id_bug(modeler: Modeler):
535535

536536
assert len(design1.components[0].bodies) == 1
537537
assert len(design1.components[1].bodies) == 1
538+
539+
540+
@pytest.mark.skip(reason="Object reference not set to an instance of an object.")
541+
def test_import_scdocx_with_external_docs(modeler: Modeler):
542+
"""Test importing an SCDOCX file with external documents and verify it is internalized."""
543+
# Create a new design
544+
design = modeler.create_design("Insert External Document")
545+
546+
# Define the path to the external SCDOCX file
547+
path_to_external_doc = Path(FILES_DIR, "external_file_scdocx", "Design1.scdocx")
548+
549+
# Import the external SCDOCX file
550+
design.insert_file(file_location=path_to_external_doc)
551+
552+
# Verify that the design structure is internalized
553+
# Check the number of bodies in the design
554+
assert len(design.bodies) == 0
555+
556+
# Check the number of components in the design
557+
assert len(design.components) == 1
558+
559+
# Check the number of bodies in the first component
560+
assert len(design.components[0].bodies) == 1
561+
562+
# Check the number of subcomponents in the first component
563+
assert len(design.components[0].components) == 5
564+
565+
for component in design.components[0].components:
566+
assert len(component.bodies) == 1

tests/test_connection.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,14 @@ def test_is_port_available():
430430
"""Test that _is_port_available correctly detects available and unavailable ports."""
431431
host = "localhost"
432432

433+
# Dynamically find an available port
434+
available_port = find_available_port()
435+
433436
# Test an available port
434-
available_port = 5000
435437
assert _is_port_available(available_port, host) is True
436438

437439
# Test an unavailable port by binding it
438-
unavailable_port = 5001
440+
unavailable_port = find_available_port()
439441
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
440442
s.bind((host, unavailable_port)) # Bind the port to make it unavailable
441443
assert _is_port_available(unavailable_port, host) is False
@@ -519,14 +521,21 @@ def test_check_minimal_versions(
519521
pytest.fail("SystemError raised unexpectedly.")
520522

521523

524+
def find_available_port():
525+
"""Find an available port for testing."""
526+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
527+
s.bind(("127.0.0.1", 0)) # Bind to an available port on the loopback interface
528+
return s.getsockname()[1] # Return the port number
529+
530+
522531
@pytest.mark.parametrize(
523532
"port, should_raise, expected_message",
524533
[
525-
(5000, False, None), # Test for an available port
534+
(find_available_port(), False, None), # Test for an available port
526535
(
527-
5001,
536+
find_available_port(),
528537
True,
529-
"Port 5001 is already in use. Please specify a different one.",
538+
r"Port \d+ is already in use\. Please specify a different one\.",
530539
), # Test for an unavailable port
531540
],
532541
)

tests/test_laucher.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,27 @@ def test_docker_not_available(monkeypatch):
125125
# Replace the launch_docker_modeler function with a dummy function
126126
monkeypatch.setattr(
127127
"ansys.geometry.core.connection.launcher.launch_docker_modeler",
128-
dummy_launch_docker_modeler,
128+
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("Docker not available")),
129+
)
130+
131+
# Monkeypatch other fallback methods to simulate failure
132+
monkeypatch.setattr(
133+
"ansys.geometry.core.connection.launcher.launch_modeler_with_core_service",
134+
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("Core service not available")),
135+
)
136+
monkeypatch.setattr(
137+
"ansys.geometry.core.connection.launcher.launch_modeler_with_geometry_service",
138+
lambda **kwargs: (_ for _ in ()).throw(
139+
NotImplementedError("Geometry service not available")
140+
),
141+
)
142+
monkeypatch.setattr(
143+
"ansys.geometry.core.connection.launcher.launch_modeler_with_spaceclaim",
144+
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("SpaceClaim not available")),
145+
)
146+
monkeypatch.setattr(
147+
"ansys.geometry.core.connection.launcher.launch_modeler_with_discovery",
148+
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("Discovery not available")),
129149
)
130150

131151
# Call the function and verify that it raises NotImplementedError

0 commit comments

Comments
 (0)