@@ -243,3 +243,58 @@ def test_get_api_version_from_env(self, mocker):
243243 )
244244 assert isinstance (context .openai_llm_client , AzureOpenAI )
245245 assert context .openai_llm_client ._api_version == version
246+
247+ def test_disable_ai_client_openai (self , mocker ):
248+ mocker .patch .dict (os .environ , {"CODEMODDER_OPENAI_API_KEY" : "test" })
249+ context = Context (
250+ mocker .Mock (),
251+ True ,
252+ False ,
253+ load_registered_codemods (),
254+ None ,
255+ PythonRepoManager (mocker .Mock ()),
256+ [],
257+ [],
258+ ai_client = False ,
259+ )
260+ assert context .openai_llm_client is None
261+
262+ def test_disable_ai_client_azure (self , mocker ):
263+ mocker .patch .dict (
264+ os .environ ,
265+ {
266+ "CODEMODDER_AZURE_OPENAI_API_KEY" : "test" ,
267+ "CODEMODDER_AZURE_OPENAI_ENDPOINT" : "test" ,
268+ },
269+ )
270+ context = Context (
271+ mocker .Mock (),
272+ True ,
273+ False ,
274+ load_registered_codemods (),
275+ None ,
276+ PythonRepoManager (mocker .Mock ()),
277+ [],
278+ [],
279+ ai_client = False ,
280+ )
281+ assert context .openai_llm_client is None
282+
283+ @pytest .mark .parametrize (
284+ "env_var" ,
285+ ["CODEMODDER_AZURE_OPENAI_API_KEY" , "CODEMODDER_AZURE_OPENAI_ENDPOINT" ],
286+ )
287+ def test_no_misconfiguration_ai_client_disabled (self , mocker , env_var ):
288+ mocker .patch .dict (os .environ , {env_var : "test" })
289+ context = Context (
290+ mocker .Mock (),
291+ True ,
292+ False ,
293+ load_registered_codemods (),
294+ None ,
295+ PythonRepoManager (mocker .Mock ()),
296+ [],
297+ [],
298+ ai_client = False ,
299+ )
300+ assert context .openai_llm_client is None
0 commit comments