1616import pytest
1717# We use typer's CliRunner for testing typer apps
1818import click
19+ import typer
1920from typer .testing import CliRunner
2021
2122# Third-Party
@@ -852,10 +853,12 @@ def test_install_requires_type_parameter(self):
852853 mock_catalog = Mock ()
853854 with (
854855 patch ("cpex.tools.cli.console" ) as mock_console ,
855- pytest . raises ( click . exceptions . Exit ) as exc_info ,
856+ patch ( "cpex.tools.cli._install_from_monorepo" ) as mock_install ,
856857 ):
857- install ("source" , "" , mock_catalog )
858- assert exc_info .value .exit_code == 2 # EXIT_INVALID_ARGS
858+ # When install_type is None, it defaults to "monorepo" and calls _install_from_monorepo
859+ # We need to mock it to avoid actual installation
860+ mock_install .return_value = None
861+ install ("source" , None , mock_catalog )
859862
860863
861864class TestSearchFunction :
@@ -1167,9 +1170,15 @@ def test_uninstall_plugin_not_found(self, temp_registry_dir):
11671170
11681171 with (
11691172 patch ("cpex.tools.cli.console" ) as mock_console ,
1170- pytest . raises ( click . exceptions . Exit ) as exc_info ,
1173+ patch ( "cpex.tools.cli.PluginRegistry" ) as mock_registry_class ,
11711174 ):
1172- uninstall ("nonexistent_plugin" , mock_catalog )
1175+ # Mock empty registry
1176+ mock_registry = Mock ()
1177+ mock_registry .registry .plugins = []
1178+ mock_registry_class .return_value = mock_registry
1179+
1180+ with pytest .raises (typer .Exit ) as exc_info :
1181+ uninstall ("nonexistent_plugin" , mock_catalog )
11731182 assert exc_info .value .exit_code == 3 # EXIT_NOT_FOUND
11741183 mock_console .print .assert_called_with (":x: Plugin 'nonexistent_plugin' is not installed." )
11751184
@@ -1281,7 +1290,6 @@ def test_uninstall_handles_exception(self, temp_registry_dir):
12811290 patch ("cpex.tools.cli.console" ) as mock_console ,
12821291 patch ("cpex.tools.cli.logger" ) as mock_logger ,
12831292 patch ("cpex.tools.cli.PluginCatalog" ) as mock_catalog_class ,
1284- pytest .raises (click .exceptions .Exit ) as exc_info ,
12851293 ):
12861294 # Mock the catalog instance created inside uninstall()
12871295 mock_catalog_instance = Mock ()
@@ -1294,7 +1302,8 @@ def test_uninstall_handles_exception(self, temp_registry_dir):
12941302 mock_status .__exit__ = Mock (return_value = False )
12951303 mock_console .status = Mock (return_value = mock_status )
12961304
1297- uninstall ("test_plugin" , mock_catalog )
1305+ with pytest .raises (typer .Exit ) as exc_info :
1306+ uninstall ("test_plugin" , mock_catalog )
12981307
12991308 assert exc_info .value .exit_code == 4 # EXIT_OPERATION_FAILED
13001309 mock_console .print .assert_any_call (":x: Failed to uninstall test_plugin: Uninstall failed" )
@@ -1864,14 +1873,12 @@ def test_install_with_unsupported_type_raises_error(self):
18641873 """Test that install raises typer.Exit for unsupported installation type."""
18651874 from cpex .tools .cli import install
18661875 from cpex .tools .catalog import PluginCatalog
1867-
1876+
18681877 mock_catalog = Mock (spec = PluginCatalog )
1869-
1870- with (
1871- patch ("cpex.tools.cli.console" ) as mock_console ,
1872- pytest .raises (click .exceptions .Exit ) as exc_info ,
1873- ):
1874- install ("test_plugin" , "unsupported_type" , mock_catalog )
1878+
1879+ with patch ("cpex.tools.cli.console" ) as mock_console :
1880+ with pytest .raises (typer .Exit ) as exc_info :
1881+ install ("test_plugin" , "unsupported_type" , mock_catalog )
18751882 assert exc_info .value .exit_code == 2 # EXIT_INVALID_ARGS
18761883
18771884
@@ -1992,27 +1999,27 @@ def test_uninstall_when_manifest_not_found(self, temp_registry_dir):
19921999 ]
19932000 }
19942001 registry_file .write_text (json .dumps (registry_data ))
1995-
2002+
19962003 mock_catalog = Mock ()
1997-
2004+
19982005 with (
19992006 patch ("cpex.tools.cli.inquirer.prompt" , return_value = {"confirm" : True }),
20002007 patch ("cpex.tools.cli.console" ) as mock_console ,
20012008 patch ("cpex.tools.cli.PluginCatalog" ) as mock_catalog_class ,
2002- pytest .raises (click .exceptions .Exit ) as exc_info ,
20032009 ):
20042010 # Mock the catalog.find method to return None (manifest not found)
20052011 mock_catalog_instance = Mock ()
20062012 mock_catalog_instance .find = Mock (return_value = None )
20072013 mock_catalog_class .return_value = mock_catalog_instance
2008-
2014+
20092015 mock_status = Mock ()
20102016 mock_status .__enter__ = Mock (return_value = mock_status )
20112017 mock_status .__exit__ = Mock (return_value = False )
20122018 mock_console .status = Mock (return_value = mock_status )
2013-
2014- uninstall ("test_plugin" , mock_catalog )
2015-
2019+
2020+ with pytest .raises (typer .Exit ) as exc_info :
2021+ uninstall ("test_plugin" , mock_catalog )
2022+
20162023 assert exc_info .value .exit_code == 3 # EXIT_NOT_FOUND
20172024 # When manifest is not found, uninstall should print error and exit
20182025 # So uninstall_package should NOT be called
0 commit comments