Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions guardrails/cli/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def save_configuration_file(
rc_file.writelines(lines)
rc_file.close()

settings._initialize()


def _get_default_token() -> str:
"""Get the default token from the configuration file."""
Expand Down Expand Up @@ -106,6 +108,7 @@ def configure(

try:
save_configuration_file(token, enable_metrics, remote_inferencing)
# update setting singleton
logger.info("Configuration saved.")
except Exception as e:
logger.error("An unexpected error occured saving configuration!")
Expand Down
7 changes: 6 additions & 1 deletion tests/unit_tests/cli/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def test_save_configuration_file(mocker):
expanduser_mock = mocker.patch("guardrails.cli.configure.expanduser")
expanduser_mock.return_value = "/Home"

rcexpanduser_mock = mocker.patch("guardrails.classes.rc.expanduser")
rcexpanduser_mock.return_value = "/Home"

import os

join_spy = mocker.spy(os.path, "join")
Expand All @@ -88,7 +91,9 @@ def test_save_configuration_file(mocker):
save_configuration_file("token", True)

assert expanduser_mock.called is True
join_spy.assert_called_once_with("/Home", ".guardrailsrc")
assert rcexpanduser_mock.called is True
join_spy.assert_called_with("/Home", ".guardrailsrc")
assert join_spy.call_count == 2

assert mock_open.call_count == 1
writelines_spy.assert_called_once_with(
Expand Down
Loading