Skip to content

Commit

Permalink
Update topenAIChat.m
Browse files Browse the repository at this point in the history
  • Loading branch information
vpapanasta committed Apr 30, 2024
1 parent 5ce5953 commit c0bf8bf
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions tests/topenAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

% Copyright 2023-2024 The MathWorks, Inc.

methods (TestClassSetup)
function saveEnvVar(testCase)
% Ensures key is not in environment variable for tests
openAIEnvVar = "OPENAI_API_KEY";
if isenv(openAIEnvVar)
key = getenv(openAIEnvVar);
unsetenv(openAIEnvVar);
testCase.addTeardown(@(x) setenv(openAIEnvVar, x), key);
end
end
end

properties(TestParameter)
InvalidConstructorInput = iGetInvalidConstructorInput();
InvalidGenerateInput = iGetInvalidGenerateInput();
Expand Down Expand Up @@ -44,6 +32,7 @@ function generateOpenAIChatWithDefaultNVPValues(testCase)
end

function keyNotFound(testCase)
iSaveEnvVar(testCase);
testCase.verifyError(@()openAIChat, "llms:keyMustBeSpecified");
end

Expand Down Expand Up @@ -469,4 +458,14 @@ function createOpenAIChatWithOpenAIKey(testCase)
"InvalidSeed",struct( ...
"Input",{{ validMessages "Seed" "2" }},...
"Error","MATLAB:validators:mustBeNumericOrLogical"));
end

function iSaveEnvVar(testCase)
% Ensures key is not in environment variable for tests
openAIEnvVar = "OPENAI_API_KEY";
if isenv(openAIEnvVar)
key = getenv(openAIEnvVar);
unsetenv(openAIEnvVar);
testCase.addTeardown(@(x) setenv(openAIEnvVar, x), key);
end
end

0 comments on commit c0bf8bf

Please sign in to comment.