Skip to content

Commit b5a4a4e

Browse files
committed
Decorate tests with patch
1 parent 50232db commit b5a4a4e

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

tests/unit/test_cli.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -627,49 +627,47 @@ def test_panels_add_personal_lib_not_directory(cli_runner, tmp_path):
627627
assert "not a directory" in result.stdout
628628

629629

630-
def test_panels_add_installer_returns_false(cli_runner, temp_personal_lib):
630+
@patch("ansys.aedt.core.extensions.installer.pyaedt_installer.add_pyaedt_to_aedt", return_value=False)
631+
def test_panels_add_installer_returns_false(mock_func, cli_runner, temp_personal_lib):
631632
"""Test panel installation when installer returns False."""
632-
with patch("ansys.aedt.core.extensions.installer.pyaedt_installer.add_pyaedt_to_aedt") as mock_func:
633-
mock_func.return_value = False
634-
635-
result = cli_runner.invoke(
636-
app,
637-
["panels", "add", "--version", "2025.2", "--personal-lib", str(temp_personal_lib)],
638-
)
633+
result = cli_runner.invoke(
634+
app,
635+
["panels", "add", "--version", "2025.2", "--personal-lib", str(temp_personal_lib)],
636+
)
639637

640-
assert result.exit_code == 1
641-
assert "✗ Failed to install PyAEDT panels" in result.stdout
638+
assert result.exit_code == 1
639+
assert "✗ Failed to install PyAEDT panels" in result.stdout
642640

643641

644-
def test_panels_add_import_error(cli_runner, temp_personal_lib):
642+
@patch(
643+
"ansys.aedt.core.extensions.installer.pyaedt_installer.add_pyaedt_to_aedt",
644+
side_effect=ImportError("Cannot import installer"),
645+
)
646+
def test_panels_add_import_error(mock_func, cli_runner, temp_personal_lib):
645647
"""Test panel installation when import fails."""
646-
with patch(
647-
"ansys.aedt.core.extensions.installer.pyaedt_installer.add_pyaedt_to_aedt",
648-
side_effect=ImportError("Cannot import installer"),
649-
):
650-
result = cli_runner.invoke(
651-
app,
652-
["panels", "add", "--version", "2025.2", "--personal-lib", str(temp_personal_lib)],
653-
)
648+
result = cli_runner.invoke(
649+
app,
650+
["panels", "add", "--version", "2025.2", "--personal-lib", str(temp_personal_lib)],
651+
)
654652

655-
assert result.exit_code == 1
656-
assert "✗ Import error: Cannot import installer" in result.stdout
657-
assert "Make sure PyAEDT is properly installed" in result.stdout
653+
assert result.exit_code == 1
654+
assert "✗ Import error: Cannot import installer" in result.stdout
655+
assert "Make sure PyAEDT is properly installed" in result.stdout
658656

659657

660-
def test_panels_add_generic_exception(cli_runner, temp_personal_lib):
658+
@patch(
659+
"ansys.aedt.core.extensions.installer.pyaedt_installer.add_pyaedt_to_aedt",
660+
side_effect=Exception("Unexpected error"),
661+
)
662+
def test_panels_add_generic_exception(mock_func, cli_runner, temp_personal_lib):
661663
"""Test panel installation when generic exception occurs."""
662-
with patch(
663-
"ansys.aedt.core.extensions.installer.pyaedt_installer.add_pyaedt_to_aedt",
664-
side_effect=Exception("Unexpected error"),
665-
):
666-
result = cli_runner.invoke(
667-
app,
668-
["panels", "add", "--version", "2025.2", "--personal-lib", str(temp_personal_lib)],
669-
)
664+
result = cli_runner.invoke(
665+
app,
666+
["panels", "add", "--version", "2025.2", "--personal-lib", str(temp_personal_lib)],
667+
)
670668

671-
assert result.exit_code == 1
672-
assert "✗ Error installing panels: Unexpected error" in result.stdout
669+
assert result.exit_code == 1
670+
assert "✗ Error installing panels: Unexpected error" in result.stdout
673671

674672

675673
@patch("platform.system", return_value="Windows")

0 commit comments

Comments
 (0)