Skip to content

Commit 0d1367a

Browse files
fixed tests
1 parent 3b78114 commit 0d1367a

File tree

3 files changed

+50
-43
lines changed

3 files changed

+50
-43
lines changed

guardrails/hub/validator_package_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def install_hub_module(
289289
guardrails_token = settings.rc.token
290290

291291
pip_flags = [
292-
f"--index-url=https://__token__:{guardrails_token}@e4c4zula06.execute-api.us-east-1.amazonaws.com/simple",
292+
f"--index-url=https://__token__:{guardrails_token}@pypi.guardrailsai.com/simple",
293293
"--extra-index-url=https://pypi.org/simple",
294294
]
295295

tests/unit_tests/hub/test_hub_install.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestInstall:
1818
def setup_method(self):
1919
self.manifest = Manifest.from_dict(
2020
{
21-
"id": "id",
21+
"id": "guardrails/id",
2222
"name": "name",
2323
"author": {"name": "me", "email": "[email protected]"},
2424
"maintainers": [],
@@ -74,32 +74,30 @@ def test_install_local_models__false(self, mocker, use_remote_inferencing):
7474
)
7575

7676
install(
77-
"hub://guardrails/test-validator",
77+
"hub://guardrails/id",
7878
install_local_models=False,
7979
install_local_models_confirm=lambda: False,
8080
)
8181

8282
log_calls = [
83-
call(level=5, msg="Installing hub://guardrails/test-validator..."),
83+
call(level=5, msg="Installing hub://guardrails/id..."),
8484
call(
8585
level=5,
8686
msg="Skipping post install, models will not be downloaded for local "
8787
"inference.",
8888
),
8989
call(
9090
level=5,
91-
msg="✅Successfully installed hub://guardrails/test-validator!\n\nImport validator:\nfrom guardrails.hub import TestValidator\n\nGet more info:\nhttps://hub.guardrailsai.com/validator/id\n", # noqa
91+
msg="✅Successfully installed hub://guardrails/id!\n\nImport validator:\nfrom guardrails.hub import TestValidator\n\nGet more info:\nhttps://hub.guardrailsai.com/validator/guardrails/id\n", # noqa
9292
), # noqa
9393
]
9494
assert mock_logger_log.call_count == 3
9595
mock_logger_log.assert_has_calls(log_calls)
9696

97-
get_manifest_and_site_packages_mock.assert_called_once_with(
98-
"guardrails/test-validator"
99-
)
97+
get_manifest_and_site_packages_mock.assert_called_once_with("guardrails/id")
10098

10199
mock_pip_install_hub_module.assert_called_once_with(
102-
self.manifest, self.site_packages, quiet=ANY, upgrade=ANY, logger=ANY
100+
self.manifest.id, validator_version=None, quiet=ANY, upgrade=ANY, logger=ANY
103101
)
104102
mock_add_to_hub_init.assert_called_once_with(self.manifest, self.site_packages)
105103

@@ -117,6 +115,9 @@ def test_install_local_models__true(self, mocker, use_remote_inferencing):
117115

118116
mock_logger_log = mocker.patch("guardrails.hub.install.cli_logger.log")
119117

118+
pkg_resources = mocker.patch("guardrails.hub.install.pkg_resources")
119+
pkg_resources.get_distribution.return_value.version = "1.0.0"
120+
120121
get_manifest_and_site_packages_mock = mocker.patch(
121122
"guardrails.hub.validator_package_service.ValidatorPackageService.get_manifest_and_site_packages"
122123
)
@@ -136,31 +137,29 @@ def test_install_local_models__true(self, mocker, use_remote_inferencing):
136137
)
137138

138139
install(
139-
"hub://guardrails/test-validator",
140+
"hub://guardrails/id",
140141
install_local_models=True,
141142
install_local_models_confirm=lambda: True,
142143
)
143144

144145
log_calls = [
145-
call(level=5, msg="Installing hub://guardrails/test-validator..."),
146+
call(level=5, msg="Installing hub://guardrails/id..."),
146147
call(
147148
level=5,
148149
msg="Installing models locally!",
149150
),
150151
call(
151152
level=5,
152-
msg="✅Successfully installed hub://guardrails/test-validator!\n\nImport validator:\nfrom guardrails.hub import TestValidator\n\nGet more info:\nhttps://hub.guardrailsai.com/validator/id\n", # noqa
153+
msg="✅Successfully installed hub://guardrails/id!\n\nImport validator:\nfrom guardrails.hub import TestValidator\n\nGet more info:\nhttps://hub.guardrailsai.com/validator/guardrails/id\n", # noqa
153154
), # noqa
154155
]
155156
assert mock_logger_log.call_count == 3
156157
mock_logger_log.assert_has_calls(log_calls)
157158

158-
get_manifest_and_site_packages_mock.assert_called_once_with(
159-
"guardrails/test-validator"
160-
)
159+
get_manifest_and_site_packages_mock.assert_called_once_with("guardrails/id")
161160

162161
mock_pip_install_hub_module.assert_called_once_with(
163-
self.manifest, self.site_packages, quiet=ANY, upgrade=ANY, logger=ANY
162+
self.manifest.id, validator_version=None, quiet=ANY, upgrade=ANY, logger=ANY
164163
)
165164
mock_add_to_hub_init.assert_called_once_with(self.manifest, self.site_packages)
166165

@@ -197,31 +196,29 @@ def test_install_local_models__none(self, mocker, use_remote_inferencing):
197196
)
198197

199198
install(
200-
"hub://guardrails/test-validator",
199+
"hub://guardrails/id",
201200
install_local_models=None,
202201
install_local_models_confirm=lambda: True,
203202
)
204203

205204
log_calls = [
206-
call(level=5, msg="Installing hub://guardrails/test-validator..."),
205+
call(level=5, msg="Installing hub://guardrails/id..."),
207206
call(
208207
level=5,
209208
msg="Installing models locally!",
210209
),
211210
call(
212211
level=5,
213-
msg="✅Successfully installed hub://guardrails/test-validator!\n\nImport validator:\nfrom guardrails.hub import TestValidator\n\nGet more info:\nhttps://hub.guardrailsai.com/validator/id\n", # noqa
212+
msg="✅Successfully installed hub://guardrails/id!\n\nImport validator:\nfrom guardrails.hub import TestValidator\n\nGet more info:\nhttps://hub.guardrailsai.com/validator/guardrails/id\n", # noqa
214213
), # noqa
215214
]
216215
assert mock_logger_log.call_count == 3
217216
mock_logger_log.assert_has_calls(log_calls)
218217

219-
get_manifest_and_site_packages_mock.assert_called_once_with(
220-
"guardrails/test-validator"
221-
)
218+
get_manifest_and_site_packages_mock.assert_called_once_with("guardrails/id")
222219

223220
mock_pip_install_hub_module.assert_called_once_with(
224-
self.manifest, self.site_packages, quiet=ANY, upgrade=ANY, logger=ANY
221+
self.manifest.id, validator_version=None, quiet=ANY, upgrade=ANY, logger=ANY
225222
)
226223
mock_add_to_hub_init.assert_called_once_with(self.manifest, self.site_packages)
227224

@@ -258,12 +255,12 @@ def test_happy_path(self, mocker, use_remote_inferencing):
258255
)
259256

260257
install(
261-
"hub://guardrails/test-validator",
258+
"hub://guardrails/id",
262259
install_local_models_confirm=lambda: True,
263260
)
264261

265262
log_calls = [
266-
call(level=5, msg="Installing hub://guardrails/test-validator..."),
263+
call(level=5, msg="Installing hub://guardrails/id..."),
267264
call(
268265
level=5,
269266
msg="Installing models locally!", # noqa
@@ -273,12 +270,10 @@ def test_happy_path(self, mocker, use_remote_inferencing):
273270
assert mock_logger_log.call_count == 3
274271
mock_logger_log.assert_has_calls(log_calls)
275272

276-
get_manifest_and_site_packages_mock.assert_called_once_with(
277-
"guardrails/test-validator"
278-
)
273+
get_manifest_and_site_packages_mock.assert_called_once_with("guardrails/id")
279274

280275
mock_pip_install_hub_module.assert_called_once_with(
281-
self.manifest, self.site_packages, quiet=ANY, upgrade=ANY, logger=ANY
276+
self.manifest.id, validator_version=None, quiet=ANY, upgrade=ANY, logger=ANY
282277
)
283278
mock_add_to_hub_init.assert_called_once_with(self.manifest, self.site_packages)
284279

@@ -408,7 +403,7 @@ def test_use_remote_endpoint(self, mocker, use_remote_inferencing: bool):
408403

409404
manifest = Manifest.from_dict(
410405
{
411-
"id": "id",
406+
"id": "guardrails/test-validator",
412407
"name": "name",
413408
"author": {"name": "me", "email": "[email protected]"},
414409
"maintainers": [],

tests/unit_tests/hub/test_validator_package_service.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TestAddToHubInits:
4848
def test_closes_early_if_already_added(self, mocker):
4949
manifest = Manifest.from_dict(
5050
{
51-
"id": "id",
51+
"id": "guardrails-ai/id",
5252
"name": "name",
5353
"author": {"name": "me", "email": "[email protected]"},
5454
"maintainers": [],
@@ -69,14 +69,18 @@ def test_closes_early_if_already_added(self, mocker):
6969
mock_open.side_effect = [hub_init_file, ns_init_file]
7070

7171
mock_hub_read = mocker.patch.object(hub_init_file, "read")
72-
mock_hub_read.return_value = "from guardrails.hub.guardrails_ai.test_validator.validator import helper, TestValidator" # noqa
72+
mock_hub_read.return_value = (
73+
"from guardrails_ai_grhub_id import helper, TestValidator" # noqa
74+
)
7375

7476
hub_seek_spy = mocker.spy(hub_init_file, "seek")
7577
hub_write_spy = mocker.spy(hub_init_file, "write")
7678
hub_close_spy = mocker.spy(hub_init_file, "close")
7779

7880
mock_ns_read = mocker.patch.object(ns_init_file, "read")
79-
mock_ns_read.return_value = "from guardrails.hub.guardrails_ai.test_validator.validator import helper, TestValidator" # noqa
81+
mock_ns_read.return_value = (
82+
"from guardrails_ai_grhub_id import helper, TestValidator" # noqa
83+
)
8084

8185
ns_seek_spy = mocker.spy(ns_init_file, "seek")
8286
ns_write_spy = mocker.spy(ns_init_file, "write")
@@ -115,7 +119,7 @@ def test_closes_early_if_already_added(self, mocker):
115119
def test_appends_import_line_if_not_present(self, mocker):
116120
manifest = Manifest.from_dict(
117121
{
118-
"id": "id",
122+
"id": "guardrails-ai/id",
119123
"name": "name",
120124
"author": {"name": "me", "email": "[email protected]"},
121125
"maintainers": [],
@@ -176,7 +180,7 @@ def test_appends_import_line_if_not_present(self, mocker):
176180
hub_write_calls = [
177181
call("\n"),
178182
call(
179-
"from guardrails.hub.guardrails_ai.test_validator.validator import TestValidator" # noqa
183+
"from guardrails_ai_grhub_id import TestValidator" # noqa
180184
),
181185
]
182186
hub_write_spy.assert_has_calls(hub_write_calls)
@@ -194,14 +198,14 @@ def test_appends_import_line_if_not_present(self, mocker):
194198
assert mock_ns_read.call_count == 1
195199
assert ns_write_spy.call_count == 1
196200
ns_write_spy.assert_called_once_with(
197-
"from guardrails.hub.guardrails_ai.test_validator.validator import TestValidator" # noqa
201+
"from guardrails_ai_grhub_id import TestValidator" # noqa
198202
)
199203
assert ns_close_spy.call_count == 1
200204

201205
def test_creates_namespace_init_if_not_exists(self, mocker):
202206
manifest = Manifest.from_dict(
203207
{
204-
"id": "id",
208+
"id": "guardrails-ai/id",
205209
"name": "name",
206210
"author": {"name": "me", "email": "[email protected]"},
207211
"maintainers": [],
@@ -222,7 +226,7 @@ def test_creates_namespace_init_if_not_exists(self, mocker):
222226
mock_open.side_effect = [hub_init_file, ns_init_file]
223227

224228
mock_hub_read = mocker.patch.object(hub_init_file, "read")
225-
mock_hub_read.return_value = "from guardrails.hub.guardrails_ai.test_validator.validator import TestValidator" # noqa
229+
mock_hub_read.return_value = "from guardrails_ai_grhub_id import TestValidator" # noqa
226230

227231
mock_ns_read = mocker.patch.object(ns_init_file, "read")
228232
mock_ns_read.return_value = ""
@@ -256,7 +260,7 @@ def test_creates_namespace_init_if_not_exists(self, mocker):
256260
assert mock_ns_read.call_count == 0
257261
assert ns_write_spy.call_count == 1
258262
ns_write_spy.assert_called_once_with(
259-
"from guardrails.hub.guardrails_ai.test_validator.validator import TestValidator" # noqa
263+
"from guardrails_ai_grhub_id import TestValidator" # noqa
260264
)
261265
assert ns_close_spy.call_count == 1
262266

@@ -417,7 +421,7 @@ def test_runs_script_if_exists(self, mocker):
417421
mock_subprocess_check_output.assert_called_once_with(
418422
[
419423
mock_sys_executable,
420-
"./site_packages/guardrails/hub/guardrails_ai/test_validator/validator/post_install.py", # noqa
424+
"./site_packages/guardrails_ai_grhub_id/post_install.py", # noqa
421425
]
422426
)
423427

@@ -512,7 +516,7 @@ def test_get_validator_from_manifest(self, mock_reload_module):
512516
"author": {"name": "me", "email": "[email protected]"},
513517
"maintainers": [],
514518
"repository": {"url": "some-repo"},
515-
"namespace": "guardrails-ai",
519+
"namespace": "",
516520
"packageName": "test-validator",
517521
"moduleName": "test_validator",
518522
"description": "description",
@@ -545,6 +549,11 @@ def test_install_hub_module(self, mocker):
545549
mock_pip_process = mocker.patch(
546550
"guardrails.hub.validator_package_service.pip_process"
547551
)
552+
mock_settings = mocker.patch(
553+
"guardrails.hub.validator_package_service.settings"
554+
)
555+
mock_settings.rc.token = "mock-token"
556+
548557
inspect_report = {
549558
"installed": [
550559
{
@@ -589,8 +598,11 @@ def test_install_hub_module(self, mocker):
589598
pip_calls = [
590599
call(
591600
"install",
592-
"mock-install-url",
593-
["--target=mock/install/directory", "--no-deps"],
601+
"guardrails-ai-grhub-id",
602+
[
603+
"--index-url=https://__token__:[email protected]/simple",
604+
"--extra-index-url=https://pypi.org/simple",
605+
],
594606
quiet=False,
595607
),
596608
]

0 commit comments

Comments
 (0)