MCPcopy Create free account
hub / github.com/mlco2/codecarbon / test_init_use_local

Method test_init_use_local

tests/cli/test_cli.py:154–182  ·  view source on GitHub ↗
(
        self, mock_prompt, mock_config, mock_path_exists, mock_token, MockApiClient
    )

Source from the content-addressed store, hash-verified

152 @patch("codecarbon.cli.main.get_config")
153 @patch("codecarbon.cli.main.questionary_prompt")
154 def test_init_use_local(
155 self, mock_prompt, mock_config, mock_path_exists, mock_token, MockApiClient
156 ):
157 mock_prompt.return_value = "~/.codecarbon.config"
158 mock_config.return_value = {
159 "api_endpoint": "http://localhost:8008",
160 "organization_id": "114",
161 "project_id": "133",
162 "experiment_id": "yolo123",
163 }
164 mock_token.return_value = "mock_token"
165
166 def side_effect_wrapper(*args, **kwargs):
167 """Side effect wrapper to simulate the first call to path.exists to avoid picking up global config"""
168 if side_effect_wrapper.call_count == 1:
169 side_effect_wrapper.call_count += 1
170 return False
171 else:
172 side_effect_wrapper.call_count += 1
173 return True
174
175 side_effect_wrapper.call_count = 0
176 mock_path_exists.side_effects = side_effect_wrapper
177 result = self.runner.invoke(codecarbon, ["config"], input="n")
178 self.assertEqual(result.exit_code, 0)
179 self.assertIn(
180 "Using already existing global config file ",
181 result.stdout,
182 )
183
184 def custom_questionary_side_effect(*args, **kwargs):
185 default_value = kwargs.get("default")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected