3
3
4
4
% Copyright 2023-2024 The MathWorks, Inc.
5
5
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
-
18
6
properties (TestParameter )
19
7
InvalidConstructorInput = iGetInvalidConstructorInput();
20
8
InvalidGenerateInput = iGetInvalidGenerateInput();
@@ -44,6 +32,7 @@ function generateOpenAIChatWithDefaultNVPValues(testCase)
44
32
end
45
33
46
34
function keyNotFound(testCase )
35
+ iSaveEnvVar(testCase );
47
36
testCase .verifyError(@()openAIChat , " llms:keyMustBeSpecified" );
48
37
end
49
38
@@ -469,4 +458,14 @@ function createOpenAIChatWithOpenAIKey(testCase)
469
458
" InvalidSeed" ,struct( ...
470
459
" Input" ,{{ validMessages " Seed" " 2" }},...
471
460
" 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
472
471
end
0 commit comments