diff --git a/doc/changelog.d/2109.test.md b/doc/changelog.d/2109.test.md new file mode 100644 index 0000000000..b9a341873b --- /dev/null +++ b/doc/changelog.d/2109.test.md @@ -0,0 +1 @@ +Internalize external documents \ No newline at end of file diff --git a/tests/integration/files/external_file_scdocx/Component1.scdocx b/tests/integration/files/external_file_scdocx/Component1.scdocx new file mode 100644 index 0000000000..96008549ae Binary files /dev/null and b/tests/integration/files/external_file_scdocx/Component1.scdocx differ diff --git a/tests/integration/files/external_file_scdocx/Component2.scdocx b/tests/integration/files/external_file_scdocx/Component2.scdocx new file mode 100644 index 0000000000..ba0493df1e Binary files /dev/null and b/tests/integration/files/external_file_scdocx/Component2.scdocx differ diff --git a/tests/integration/files/external_file_scdocx/Component3.scdocx b/tests/integration/files/external_file_scdocx/Component3.scdocx new file mode 100644 index 0000000000..61f6152b29 Binary files /dev/null and b/tests/integration/files/external_file_scdocx/Component3.scdocx differ diff --git a/tests/integration/files/external_file_scdocx/Component4.scdocx b/tests/integration/files/external_file_scdocx/Component4.scdocx new file mode 100644 index 0000000000..3eb40a7078 Binary files /dev/null and b/tests/integration/files/external_file_scdocx/Component4.scdocx differ diff --git a/tests/integration/files/external_file_scdocx/Component5.scdocx b/tests/integration/files/external_file_scdocx/Component5.scdocx new file mode 100644 index 0000000000..f6ec9cca06 Binary files /dev/null and b/tests/integration/files/external_file_scdocx/Component5.scdocx differ diff --git a/tests/integration/files/external_file_scdocx/Design1.scdocx b/tests/integration/files/external_file_scdocx/Design1.scdocx new file mode 100644 index 0000000000..ff3ac59135 Binary files /dev/null and b/tests/integration/files/external_file_scdocx/Design1.scdocx differ diff --git a/tests/integration/test_design_import.py b/tests/integration/test_design_import.py index d1718ebed3..34ac8b3d85 100644 --- a/tests/integration/test_design_import.py +++ b/tests/integration/test_design_import.py @@ -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 diff --git a/tests/test_connection.py b/tests/test_connection.py index 04ba1207ec..11f097a907 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -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 @@ -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 ], ) diff --git a/tests/test_laucher.py b/tests/test_laucher.py index 639e2ed2da..ee918b2763 100644 --- a/tests/test_laucher.py +++ b/tests/test_laucher.py @@ -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