55from guardrails_hub_types import Manifest
66from guardrails .cli .hub .uninstall import remove_from_hub_inits
77
8- manifest_mock = Manifest (
9- encoder = "some_encoder" ,
10- id = "module_id" ,
11- name = "test_module" ,
12- author = {
"name" :
"Author Name" ,
"email" :
"[email protected] " },
13- maintainers = [{
"name" :
"Maintainer Name" ,
"email" :
"[email protected] " }],
14- repository = {"url" : "https://github.com/example/repo" },
15- namespace = "guardrails" ,
16- package_name = "test_package" ,
17- description = "Test module" ,
18- module_name = "test_module" ,
19- exports = ["Validator" , "Helper" ],
8+ manifest_mock = Manifest .from_dict (
9+ {
10+ "id" : "guardrails/test_package" ,
11+ "name" : "test_module" ,
12+ "author" : {
"name" :
"Author Name" ,
"email" :
"[email protected] " },
13+ "maintainers" : [{
"name" :
"Maintainer Name" ,
"email" :
"[email protected] " }],
14+ "repository" : {"url" : "https://github.com/example/repo" },
15+ "packageName" : "test_package" ,
16+ "moduleName" : "test_module" ,
17+ "namespace" : "guardrails" ,
18+ "description" : "Test module" ,
19+ "exports" : ["Validator" , "Helper" ],
20+ }
2021)
2122
2223
2324def test_remove_from_hub_inits (mocker ):
24- mocker .patch (
25- "guardrails.cli.hub.uninstall.get_org_and_package_dirs" ,
26- return_value = ["guardrails" , "test_package" ],
27- )
2825 mock_remove_line = mocker .patch ("guardrails.cli.hub.uninstall.remove_line" )
29- mock_remove_dirs = mocker .patch ("shutil.rmtree" )
3026
3127 remove_from_hub_inits (manifest_mock , "/site-packages" )
3228
3329 expected_calls = [
3430 call (
3531 "/site-packages/guardrails/hub/__init__.py" ,
36- "from guardrails.hub.guardrails.test_package.test_module import "
37- "Validator, Helper" ,
38- ),
39- call (
40- "/site-packages/guardrails/hub/guardrails/__init__.py" ,
41- "from guardrails.hub.guardrails.test_package.test_module import "
42- "Validator, Helper" ,
32+ "from guardrails_grhub_test_package import " "Validator, Helper" ,
4333 ),
4434 ]
4535
4636 mock_remove_line .assert_has_calls (expected_calls , any_order = True )
47- mock_remove_dirs .assert_called_once_with ("/site-packages/guardrails/hub/guardrails" )
4837
4938
5039def test_uninstall_invalid_uri (mocker ):
@@ -81,10 +70,7 @@ def test_uninstall_valid_uri(mocker):
8170 "guardrails.cli.hub.uninstall.get_validator_manifest" ,
8271 return_value = manifest_mock ,
8372 )
84- mocker .patch (
85- "guardrails.cli.hub.uninstall.get_site_packages_location" ,
86- return_value = "/site-packages" ,
87- )
73+
8874 mock_uninstall_hub_module = mocker .patch (
8975 "guardrails.cli.hub.uninstall.uninstall_hub_module"
9076 )
@@ -93,9 +79,27 @@ def test_uninstall_valid_uri(mocker):
9379 )
9480 mocker .patch ("guardrails.cli.hub.uninstall.console" )
9581
82+ validator_package_service_mock = mocker .patch (
83+ "guardrails.hub.validator_package_service.ValidatorPackageService" ,
84+ )
85+ validator_package_service_mock .get_site_packages_location .return_value = (
86+ "/site-packages"
87+ )
88+
9689 from guardrails .cli .hub .uninstall import uninstall
9790
9891 uninstall ("hub://guardrails/test-validator" )
9992
100- mock_uninstall_hub_module .assert_called_once_with (manifest_mock , "/site-packages" )
93+ mock_uninstall_hub_module .assert_called_once_with (manifest_mock )
10194 mock_remove_from_hub_inits .assert_called_once_with (manifest_mock , "/site-packages" )
95+
96+
97+ def test_uninstall_hub_module (mocker ):
98+ mock_pip_process = mocker .patch ("guardrails.cli.hub.uninstall.pip_process" )
99+ from guardrails .cli .hub .uninstall import uninstall_hub_module
100+
101+ uninstall_hub_module (manifest_mock )
102+
103+ mock_pip_process .assert_called_once_with (
104+ "uninstall" , "guardrails-grhub-test-package" , flags = ["-y" ], quiet = True
105+ )
0 commit comments