|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates. |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | +# |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in all |
| 15 | +# copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | +# SOFTWARE. |
| 24 | + |
| 25 | +from unittest.mock import MagicMock |
| 26 | +from unittest.mock import PropertyMock |
| 27 | +from unittest.mock import patch |
| 28 | + |
| 29 | +import pytest |
| 30 | + |
| 31 | +from ansys.aedt.core.internal.errors import AEDTRuntimeError |
| 32 | +from ansys.aedt.core.maxwell import Maxwell3d |
| 33 | +from ansys.aedt.core.mechanical import Mechanical |
| 34 | + |
| 35 | + |
| 36 | +@pytest.fixture |
| 37 | +def mechanical(): |
| 38 | + """Fixture used to mock the creation of a Mechanical instance.""" |
| 39 | + with patch("ansys.aedt.core.mechanical.Mechanical.__init__", lambda x: None): |
| 40 | + mock_instance = MagicMock(spec=Mechanical) |
| 41 | + yield mock_instance |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture |
| 45 | +def maxwell_3d(): |
| 46 | + """Fixture used to mock the creation of a Maxwell instance.""" |
| 47 | + with patch("ansys.aedt.core.maxwell.Maxwell3d.__init__", lambda x: None): |
| 48 | + mock_instance = MagicMock(spec=Maxwell3d) |
| 49 | + yield mock_instance |
| 50 | + |
| 51 | + |
| 52 | +@patch.object(Mechanical, "design_type", "Dummy") |
| 53 | +def test_mechanical_failure_design_type(mechanical): |
| 54 | + mechanical = Mechanical() |
| 55 | + |
| 56 | + with pytest.raises(AEDTRuntimeError): |
| 57 | + mechanical.create_em_target_design("Icepak") |
| 58 | + |
| 59 | + |
| 60 | +@patch.object(Maxwell3d, "design_type", "Maxwell 3D") |
| 61 | +def test_maxwell_failure_design(maxwell_3d): |
| 62 | + maxwell = Maxwell3d() |
| 63 | + |
| 64 | + with pytest.raises(AEDTRuntimeError): |
| 65 | + maxwell.create_em_target_design("Twinbuilder") |
| 66 | + |
| 67 | + |
| 68 | +@patch.object(Maxwell3d, "nominal_adaptive", new_callable=PropertyMock) |
| 69 | +@patch.object(Maxwell3d, "design_type", "Maxwell 3D") |
| 70 | +def test_maxwell_failure_design_type_create_target_design(mock_nominal, maxwell_3d): |
| 71 | + mock_nominal.return_value = "setup_name" |
| 72 | + maxwell = Maxwell3d() |
| 73 | + maxwell._odesign = MagicMock() |
| 74 | + |
| 75 | + with pytest.raises(AEDTRuntimeError): |
| 76 | + assert maxwell.create_em_target_design("Icepak", design_setup="Invalid") |
| 77 | + |
| 78 | + |
| 79 | +@patch.object(Maxwell3d, "nominal_adaptive", new_callable=PropertyMock) |
| 80 | +@patch.object(Maxwell3d, "design_type", "Maxwell 3D") |
| 81 | +def test_maxwell_create_target_design(mock_nominal, maxwell_3d): |
| 82 | + mock_nominal.return_value = "setup_name" |
| 83 | + maxwell = Maxwell3d() |
| 84 | + maxwell._odesign = MagicMock() |
| 85 | + |
| 86 | + assert maxwell.create_em_target_design("Icepak", design_setup="Forced") |
0 commit comments