Skip to content

Commit c0bf8bf

Browse files
committed
Update topenAIChat.m
1 parent 5ce5953 commit c0bf8bf

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tests/topenAIChat.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33

44
% Copyright 2023-2024 The MathWorks, Inc.
55

6-
methods (TestClassSetup)
7-
function saveEnvVar(testCase)
8-
% Ensures key is not in environment variable for tests
9-
openAIEnvVar = "OPENAI_API_KEY";
10-
if isenv(openAIEnvVar)
11-
key = getenv(openAIEnvVar);
12-
unsetenv(openAIEnvVar);
13-
testCase.addTeardown(@(x) setenv(openAIEnvVar, x), key);
14-
end
15-
end
16-
end
17-
186
properties(TestParameter)
197
InvalidConstructorInput = iGetInvalidConstructorInput();
208
InvalidGenerateInput = iGetInvalidGenerateInput();
@@ -44,6 +32,7 @@ function generateOpenAIChatWithDefaultNVPValues(testCase)
4432
end
4533

4634
function keyNotFound(testCase)
35+
iSaveEnvVar(testCase);
4736
testCase.verifyError(@()openAIChat, "llms:keyMustBeSpecified");
4837
end
4938

@@ -469,4 +458,14 @@ function createOpenAIChatWithOpenAIKey(testCase)
469458
"InvalidSeed",struct( ...
470459
"Input",{{ validMessages "Seed" "2" }},...
471460
"Error","MATLAB:validators:mustBeNumericOrLogical"));
461+
end
462+
463+
function iSaveEnvVar(testCase)
464+
% Ensures key is not in environment variable for tests
465+
openAIEnvVar = "OPENAI_API_KEY";
466+
if isenv(openAIEnvVar)
467+
key = getenv(openAIEnvVar);
468+
unsetenv(openAIEnvVar);
469+
testCase.addTeardown(@(x) setenv(openAIEnvVar, x), key);
470+
end
472471
end

0 commit comments

Comments
 (0)