Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3104110

Browse files
committed
Merge branch 'testUtils' into stephany/jest
2 parents94ffe7a +1d0fbf3 commit3104110

File tree

5 files changed

+148
-153
lines changed

5 files changed

+148
-153
lines changed

‎mlflow/src/tracking/ExperimentClient.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ class ExperimentClient {
180180
response.status
181181
);
182182
};
183-
184-
console.log(`Experiment ID${experiment_id} successfully deleted`);
185183
}
186184

187185
/**
@@ -212,8 +210,6 @@ class ExperimentClient {
212210
response.status
213211
);
214212
}
215-
216-
console.log(`Experiment ID${experiment_id} successfully restored`);
217213
}
218214

219215
/**
@@ -246,10 +242,6 @@ class ExperimentClient {
246242
response.status
247243
);
248244
}
249-
250-
console.log(
251-
`Experiment ID${experiment_id} successfully updated - new name is${new_name}`
252-
);
253245
}
254246

255247
/**
@@ -284,8 +276,6 @@ class ExperimentClient {
284276
response.status
285277
);
286278
}
287-
288-
console.log(`Set tag to experiment ID${experiment_id} successfully`);
289279
}
290280
}
291281

‎mlflow/src/workflows/ExperimentManager.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import RunClient from '@tracking/RunClient';
33
import{ApiError}from'@utils/apiError';
44

55
interfacekeyable{
6-
[key:string]:any
6+
[key:string]:any;
77
}
88

99
classExperimentManager{
@@ -50,7 +50,10 @@ class ExperimentManager {
5050
):Promise<object>{
5151
try{
5252
// create run
53-
construn:keyable=awaitthis.runClient.createRun(experiment_id,run_name);
53+
construn:keyable=awaitthis.runClient.createRun(
54+
experiment_id,
55+
run_name
56+
);
5457
construn_id=run.info.run_id;
5558

5659
// log metric, params, and tags via logBatch
@@ -70,10 +73,8 @@ class ExperimentManager {
7073
return(latestRunas{run_info:object}).run_info;
7174
}catch(error){
7275
if(errorinstanceofApiError){
73-
console.error(`API Error (${error.statusCode}):${error.message}`);
7476
throwerror;
7577
}else{
76-
console.error('An unexpected error occurred:',error);
7778
thrownewError();
7879
}
7980
}
@@ -118,7 +119,10 @@ class ExperimentManager {
118119
);
119120

120121
// create run
121-
construn:keyable=awaitthis.runClient.createRun(experiment_id,run_name);
122+
construn:keyable=awaitthis.runClient.createRun(
123+
experiment_id,
124+
run_name
125+
);
122126
construn_id=run.info.run_id;
123127

124128
// log metric, params, and tags via logBatch
@@ -138,10 +142,8 @@ class ExperimentManager {
138142
return(latestRunas{run_info:object}).run_info;
139143
}catch(error){
140144
if(errorinstanceofApiError){
141-
console.error(`API Error (${error.statusCode}):${error.message}`);
142145
throwerror;
143146
}else{
144-
console.error('An unexpected error occurred:',error);
145147
thrownewError();
146148
}
147149
}
@@ -207,7 +209,7 @@ class ExperimentManager {
207209
if(order===1||order==='DESC')orderString='DESC';
208210
elseif(order===-1||order==='ASC')orderString='ASC';
209211
constarg=`metrics.${primaryMetric}${orderString}`;
210-
constdata:keyable=awaitthis.runClient.searchRuns(
212+
constdata:keyable=awaitthis.runClient.searchRuns(
211213
[experiment_id],
212214
'',
213215
undefined,
@@ -234,10 +236,8 @@ class ExperimentManager {
234236
returndata.runs;
235237
}catch(error){
236238
if(errorinstanceofApiError){
237-
console.error(`API Error (${error.statusCode}):${error.message}`);
238239
throwerror;
239240
}else{
240-
console.error('An unexpected error occurred:',error);
241241
thrownewError();
242242
}
243243
}
Lines changed: 71 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
import{describe,test,expect,beforeAll,afterAll}from'@jest/globals';
22
importExperimentClientfrom'../src/tracking/ExperimentClient';
33
import{ApiError}from'../src/utils/apiError';
4-
import{Experiment}from'../src/utils/interface';
4+
import{
5+
createTestExperiment,
6+
deleteTestExperiments,
7+
experimentProperties,
8+
ExpSearchResults,
9+
TRACKING_SERVER_URI,
10+
}from'./testUtils';
511

612
describe('ExperimentClient',()=>{
713
letexperimentClient:ExperimentClient;
8-
letexperimentId:string;
9-
letexperimentName:string;
1014
consttestIds:string[]=[];
1115

1216
beforeAll(async()=>{
1317
// Add a small delay to ensure MLflow is fully ready
1418
awaitnewPromise((resolve)=>setTimeout(resolve,2000));
15-
experimentClient=newExperimentClient('http://127.0.0.1:5002');
16-
17-
// Generate the experiment ID to be used generically in later tests
18-
consttimestamp=Date.now();
19-
experimentName=`Testing${timestamp}`;
20-
experimentId=awaitexperimentClient.createExperiment(experimentName);
21-
testIds.push(experimentId);
19+
experimentClient=newExperimentClient(TRACKING_SERVER_URI);
2220
});
2321

2422
describe('createExperiment',()=>{
2523
test('should create an experiment and return the experiment ID',async()=>{
26-
consttimestamp=Date.now();
27-
consttestExperimentId=awaitexperimentClient.createExperiment(
28-
`Test experiment${timestamp}`
29-
);
24+
consttestExperimentId:string=awaitcreateTestExperiment();
3025
testIds.push(testExperimentId);
3126
expect(typeoftestExperimentId).toBe('string');
3227
expect(testExperimentId).toBeTruthy();
@@ -44,6 +39,8 @@ describe('ExperimentClient', () => {
4439
});
4540

4641
test('should throw error if name is already in use',async()=>{
42+
constexperimentName:string=`Test experiment${Date.now()}`;
43+
testIds.push(awaitexperimentClient.createExperiment(experimentName));
4744
awaitexpect(
4845
experimentClient.createExperiment(experimentName)
4946
).rejects.toThrow(ApiError);
@@ -53,18 +50,15 @@ describe('ExperimentClient', () => {
5350
describe('searchExperiment',()=>{
5451
beforeAll(async()=>{
5552
for(leti=0;i<5;i++){
56-
constnum=Math.random().toString().slice(2,11);
57-
constname=`Search test${num}`;
58-
constsearch=awaitexperimentClient.createExperiment(name);
53+
constsearch:string=awaitexperimentClient.createExperiment(
54+
`Search test${Date.now()}`
55+
);
5956
testIds.push(search);
6057
}
6158
});
6259

6360
test('should return valid search results',async()=>{
64-
constresults:{
65-
experiments?:Experiment[];
66-
next_page_token?:string;
67-
}=awaitexperimentClient.searchExperiment(
61+
constresults:ExpSearchResults=awaitexperimentClient.searchExperiment(
6862
"name LIKE 'Search test%'",
6963
4
7064
);
@@ -73,26 +67,22 @@ describe('ExperimentClient', () => {
7367
expect(results.next_page_token).toBeDefined();
7468
expect(results.experiments).toHaveLength(4);
7569
results.experiments?.forEach((result)=>{
76-
expect(result).toHaveProperty('experiment_id');
77-
expect(result).toHaveProperty('name');
78-
expect(result).toHaveProperty('artifact_location');
79-
expect(result).toHaveProperty('lifecycle_stage');
80-
expect(result).toHaveProperty('last_update_time');
81-
expect(result).toHaveProperty('creation_time');
70+
for(constpropertyofexperimentProperties){
71+
expect(result).toHaveProperty(property);
72+
}
8273
});
8374
expect(typeofresults.next_page_token).toBe('string');
8475
});
8576
});
8677

8778
describe('getExperiment',()=>{
8879
test('should return experiment information',async()=>{
89-
constexperiment=awaitexperimentClient.getExperiment(experimentId);
90-
expect(experiment).toHaveProperty('experiment_id');
91-
expect(experiment).toHaveProperty('name');
92-
expect(experiment).toHaveProperty('artifact_location');
93-
expect(experiment).toHaveProperty('lifecycle_stage');
94-
expect(experiment).toHaveProperty('last_update_time');
95-
expect(experiment).toHaveProperty('creation_time');
80+
constexpId:string=awaitcreateTestExperiment();
81+
constexperiment=awaitexperimentClient.getExperiment(expId);
82+
testIds.push(expId);
83+
for(constpropertyofexperimentProperties){
84+
expect(experiment).toHaveProperty(property);
85+
}
9686
});
9787

9888
test('should throw error if experiment ID is missing',async()=>{
@@ -103,54 +93,49 @@ describe('ExperimentClient', () => {
10393

10494
describe('getExperimentByName',()=>{
10595
test('should return experiment information',async()=>{
106-
constexperiment=awaitexperimentClient.getExperimentByName(experimentName);
107-
expect(experiment).toHaveProperty('experiment_id');
108-
expect(experiment).toHaveProperty('name');
109-
expect(experiment).toHaveProperty('artifact_location');
110-
expect(experiment).toHaveProperty('lifecycle_stage');
111-
expect(experiment).toHaveProperty('last_update_time');
112-
expect(experiment).toHaveProperty('creation_time');
96+
constname:string=`Test experiment${Date.now()}`;
97+
testIds.push(awaitexperimentClient.createExperiment(name));
98+
constexperiment=awaitexperimentClient.getExperimentByName(name);
99+
for(constpropertyofexperimentProperties){
100+
expect(experiment).toHaveProperty(property);
101+
}
113102
});
114103

115104
test('should throw error if experiment name is missing',async()=>{
116105
//@ts-expect-error: testing for missing arguments
117-
awaitexpect(experimentClient.getExperimentByName()).rejects.toThrow(ApiError);
106+
awaitexpect(experimentClient.getExperimentByName()).rejects.toThrow(
107+
ApiError
108+
);
118109
});
119110
});
120111

121112
describe('deleteExperiment',()=>{
122113
test('should delete an experiment',async()=>{
123-
constnum=Math.random().toString().slice(2,11);
124-
constname=`Test experiment${num}`;
125-
constidToDelete=awaitexperimentClient.createExperiment(name);
114+
constname:string=`Test experiment${Date.now()}`;
115+
constidToDelete:string=awaitexperimentClient.createExperiment(name);
126116
awaitexperimentClient.deleteExperiment(idToDelete);
127-
constresults:{
128-
experiments?:Experiment[];
129-
next_page_token?:string;
130-
}=awaitexperimentClient.searchExperiment(
131-
`name LIKE '${idToDelete}'`,
117+
constresults:ExpSearchResults=awaitexperimentClient.searchExperiment(
118+
`name LIKE '${name}'`,
132119
4
133120
);
134121
expect(results).toEqual({});
135122
});
136123

137124
test('should throw error if invalid experiment ID is passed in',async()=>{
138-
awaitexpect(experimentClient.deleteExperiment('invalidExperimentId')).rejects.toThrow(ApiError);
125+
awaitexpect(
126+
experimentClient.deleteExperiment('invalidExperimentId')
127+
).rejects.toThrow(ApiError);
139128
});
140129
});
141130

142131
describe('restoreExperiment',()=>{
143132
test('should restore a deleted experiment',async()=>{
144-
constnum=Math.random().toString().slice(2,11);
145-
constname=`Test experiment${num}`;
146-
constidToDelete=awaitexperimentClient.createExperiment(name);
133+
constname:string=`Test experiment${Date.now()}`;
134+
constidToDelete:string=awaitexperimentClient.createExperiment(name);
147135
testIds.push(idToDelete);
148136
awaitexperimentClient.deleteExperiment(idToDelete);
149137
awaitexperimentClient.restoreExperiment(idToDelete);
150-
constresults:{
151-
experiments?:Experiment[];
152-
next_page_token?:string;
153-
}=awaitexperimentClient.searchExperiment(
138+
constresults:ExpSearchResults=awaitexperimentClient.searchExperiment(
154139
`name LIKE '${name}'`,
155140
4
156141
);
@@ -159,22 +144,20 @@ describe('ExperimentClient', () => {
159144
});
160145

161146
test('should throw error if invalid experiment ID is passed in',async()=>{
162-
awaitexpect(experimentClient.restoreExperiment('invalidExperimentId')).rejects.toThrow(ApiError);
147+
awaitexpect(
148+
experimentClient.restoreExperiment('invalidExperimentId')
149+
).rejects.toThrow(ApiError);
163150
});
164151
});
165152

166153
describe('updateExperiment',()=>{
167-
test('should update an experiment\'s name',async()=>{
168-
constnum=Math.random().toString().slice(2,11);
169-
constname=`Test experiment${num}`;
170-
constexp=awaitexperimentClient.createExperiment(name);
154+
test("should update an experiment's name",async()=>{
155+
constname:string=`Test experiment${Date.now()}`;
156+
constexp:string=awaitexperimentClient.createExperiment(name);
171157
testIds.push(exp);
172-
constupdatedName=`${name}_UPDATE`
158+
constupdatedName:string=`${name}_UPDATE`;
173159
awaitexperimentClient.updateExperiment(exp,updatedName);
174-
constresults:{
175-
experiments?:Experiment[];
176-
next_page_token?:string;
177-
}=awaitexperimentClient.searchExperiment(
160+
constresults:ExpSearchResults=awaitexperimentClient.searchExperiment(
178161
`name LIKE '${updatedName}'`,
179162
4
180163
);
@@ -184,22 +167,24 @@ describe('ExperimentClient', () => {
184167
});
185168

186169
test('should throw error if invalid experiment ID is passed in',async()=>{
187-
awaitexpect(experimentClient.updateExperiment('invalidExperimentId','invalidExperimentIdUpdate')).rejects.toThrow(ApiError);
170+
awaitexpect(
171+
experimentClient.updateExperiment(
172+
'invalidExperimentId',
173+
'invalidExperimentIdUpdate'
174+
)
175+
).rejects.toThrow(ApiError);
188176
});
189177
});
190178

191179
describe('setExperimentTag',()=>{
192180
test('should set a tag on an experiment',async()=>{
193-
constnum=Math.random().toString().slice(2,11);
194-
constname=`Test experiment${num}`;
195-
constexp=awaitexperimentClient.createExperiment(name);
181+
constdate:number=Date.now();
182+
constname:string=`Test experiment${date}`;
183+
constexp:string=awaitexperimentClient.createExperiment(name);
196184
testIds.push(exp);
197-
awaitexperimentClient.setExperimentTag(exp,'tag1',`value${num}`);
198-
constresults:{
199-
experiments?:Experiment[];
200-
next_page_token?:string;
201-
}=awaitexperimentClient.searchExperiment(
202-
`tags.tag1 = "value${num}"`,
185+
awaitexperimentClient.setExperimentTag(exp,'tag1',`value${date}`);
186+
constresults:ExpSearchResults=awaitexperimentClient.searchExperiment(
187+
`tags.tag1 = "value${date}"`,
203188
4
204189
);
205190
expect(results.experiments).toBeDefined();
@@ -208,16 +193,15 @@ describe('ExperimentClient', () => {
208193
});
209194

210195
test('should throw error if invalid experiment ID is passed in',async()=>{
211-
awaitexpect(experimentClient.setExperimentTag('invalidExperimentId','tag1','value1')).rejects.toThrow(ApiError);
196+
awaitexpect(
197+
experimentClient.setExperimentTag(
198+
'invalidExperimentId',
199+
'tag1',
200+
'value1'
201+
)
202+
).rejects.toThrow(ApiError);
212203
});
213204
});
214205

215-
afterAll(async()=>{
216-
while(testIds.length>0){
217-
constid=testIds.pop();
218-
if(id){
219-
awaitexperimentClient.deleteExperiment(id);
220-
}
221-
}
222-
});
206+
afterAll(async()=>awaitdeleteTestExperiments(testIds));
223207
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp