Skip to content
Merged
1 change: 1 addition & 0 deletions doc/changelog.d/2109.test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Internalize external documents
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/integration/test_design_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,32 @@ def test_design_insert_id_bug(modeler: Modeler):

assert len(design1.components[0].bodies) == 1
assert len(design1.components[1].bodies) == 1


@pytest.mark.skip(reason="Object reference not set to an instance of an object.")
def test_import_scdocx_with_external_docs(modeler: Modeler):
"""Test importing an SCDOCX file with external documents and verify it is internalized."""
# Create a new design
design = modeler.create_design("Insert External Document")

# Define the path to the external SCDOCX file
path_to_external_doc = Path(FILES_DIR, "external_file_scdocx", "Design1.scdocx")

# Import the external SCDOCX file
design.insert_file(file_location=path_to_external_doc)

# Verify that the design structure is internalized
# Check the number of bodies in the design
assert len(design.bodies) == 0

# Check the number of components in the design
assert len(design.components) == 1

# Check the number of bodies in the first component
assert len(design.components[0].bodies) == 1

# Check the number of subcomponents in the first component
assert len(design.components[0].components) == 5

for component in design.components[0].components:
assert len(component.bodies) == 1
19 changes: 14 additions & 5 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,14 @@ def test_is_port_available():
"""Test that _is_port_available correctly detects available and unavailable ports."""
host = "localhost"

# Dynamically find an available port
available_port = find_available_port()

# Test an available port
available_port = 5000
assert _is_port_available(available_port, host) is True

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


def find_available_port():
"""Find an available port for testing."""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("127.0.0.1", 0)) # Bind to an available port on the loopback interface
return s.getsockname()[1] # Return the port number


@pytest.mark.parametrize(
"port, should_raise, expected_message",
[
(5000, False, None), # Test for an available port
(find_available_port(), False, None), # Test for an available port
(
5001,
find_available_port(),
True,
"Port 5001 is already in use. Please specify a different one.",
r"Port \d+ is already in use\. Please specify a different one\.",
), # Test for an unavailable port
],
)
Expand Down
22 changes: 21 additions & 1 deletion tests/test_laucher.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,27 @@ def test_docker_not_available(monkeypatch):
# Replace the launch_docker_modeler function with a dummy function
monkeypatch.setattr(
"ansys.geometry.core.connection.launcher.launch_docker_modeler",
dummy_launch_docker_modeler,
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("Docker not available")),
)

# Monkeypatch other fallback methods to simulate failure
monkeypatch.setattr(
"ansys.geometry.core.connection.launcher.launch_modeler_with_core_service",
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("Core service not available")),
)
monkeypatch.setattr(
"ansys.geometry.core.connection.launcher.launch_modeler_with_geometry_service",
lambda **kwargs: (_ for _ in ()).throw(
NotImplementedError("Geometry service not available")
),
)
monkeypatch.setattr(
"ansys.geometry.core.connection.launcher.launch_modeler_with_spaceclaim",
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("SpaceClaim not available")),
)
monkeypatch.setattr(
"ansys.geometry.core.connection.launcher.launch_modeler_with_discovery",
lambda **kwargs: (_ for _ in ()).throw(NotImplementedError("Discovery not available")),
)

# Call the function and verify that it raises NotImplementedError
Expand Down
Loading