1- import { describe , test , expect , beforeAll , jest } from '@jest/globals' ;
1+ import { describe , test , expect , beforeAll , jest , afterAll } from '@jest/globals' ;
22import RunClient from '../src/tracking/RunClient' ;
33import ModelManager from '../src/workflows/ModelManager' ;
44import ModelRegistryClient from '../src/model-registry/ModelRegistryClient' ;
@@ -29,7 +29,7 @@ describe('ModelManager', () => {
2929
3030 describe ( 'createRegisteredModelWithVersion' , ( ) => {
3131 test ( 'Should create a new registered model with a version 1' , async ( ) => {
32- const modelName2 = `createRegisteredModelWithVersion-test- model-${ timestamp } ` ;
32+ const modelName2 = `createRegisteredModelWithVersion-model-${ timestamp } ` ;
3333 const newModelVersion : keyable =
3434 await modelManager . createRegisteredModelWithVersion (
3535 modelName2 ,
@@ -38,13 +38,14 @@ describe('ModelManager', () => {
3838 ) ;
3939 expect ( newModelVersion . name ) . toBe ( modelName2 ) ;
4040 expect ( newModelVersion . version ) . toBe ( '1' ) ;
41+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
4142 } ) ;
4243 test ( 'Should throw an error for duplicate model name' , async ( ) => {
4344 // Making it so console.error doesn't show up in the console
4445 const consoleErrorMock = jest
4546 . spyOn ( global . console , 'error' )
4647 . mockImplementation ( ( ) => { } ) ;
47- const modelName3 = `createRegisteredModelWithVersionDup-test- model-${ timestamp } ` ;
48+ const modelName3 = `createRegisteredModelWithVersionDup-model-${ timestamp } ` ;
4849 await modelManager . createRegisteredModelWithVersion (
4950 modelName3 ,
5051 run . info . artifact_uri ,
@@ -62,6 +63,7 @@ describe('ModelManager', () => {
6263 expect ( consoleErrorMock ) . toHaveBeenCalled ( ) ;
6364 // restoring the console to show console.error again to not affect other tests
6465 consoleErrorMock . mockRestore ( ) ;
66+ await modelRegistryClient . deleteRegisteredModel ( modelName3 ) ;
6567 } ) ;
6668 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
6769 // Making it so console.error doesn't show up in the console
@@ -81,7 +83,7 @@ describe('ModelManager', () => {
8183
8284 describe ( 'updateRegisteredModelDescriptionAndTag' , ( ) => {
8385 test ( "Should update a registered model's description and tag" , async ( ) => {
84- const modelName2 = `updateRegisteredModelDescriptionAndTag-test- model-${ timestamp } ` ;
86+ const modelName2 = `updateRegisteredModelDescriptionAndTag-model-${ timestamp } ` ;
8587 const updateRegisteredModelDescriptionAndTagObject : keyable =
8688 await modelRegistryClient . createRegisteredModel ( modelName2 ) ;
8789 expect ( updateRegisteredModelDescriptionAndTagObject . description ) . toBe (
@@ -99,6 +101,7 @@ describe('ModelManager', () => {
99101 ) ;
100102 expect ( updatedModelDescriptionAndTag . tags [ 0 ] . key ) . toBe ( 'modelTagKey' ) ;
101103 expect ( updatedModelDescriptionAndTag . tags [ 0 ] . value ) . toBe ( 'modelTagValue' ) ;
104+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
102105 } ) ;
103106 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
104107 // Making it so console.error doesn't show up in the console
@@ -118,7 +121,7 @@ describe('ModelManager', () => {
118121
119122 describe ( 'updateAllLatestModelVersion' , ( ) => {
120123 test ( "Should update the latest model version's alias, tag, and description" , async ( ) => {
121- const modelName2 = `updateAllLatestModelVersion-test- model-${ timestamp } ` ;
124+ const modelName2 = `updateAllLatestModelVersion-model-${ timestamp } ` ;
122125 await modelManager . createRegisteredModelWithVersion (
123126 modelName2 ,
124127 run . info . artifact_uri ,
@@ -151,6 +154,7 @@ describe('ModelManager', () => {
151154 expect ( updateAllLatestModelVersionObject . tags [ 0 ] . value ) . toBe (
152155 'modelVersionTagValue'
153156 ) ;
157+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
154158 } ) ;
155159 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
156160 // Making it so console.error doesn't show up in the console
@@ -170,7 +174,7 @@ describe('ModelManager', () => {
170174
171175 describe ( 'setLatestModelVersionTag' , ( ) => {
172176 test ( 'Should add a new tag key/value for the latest version of the specified registered model' , async ( ) => {
173- const modelName2 = `setLatestModelVersionTag-test- model-${ timestamp } ` ;
177+ const modelName2 = `setLatestModelVersionTag-model-${ timestamp } ` ;
174178 await modelManager . createRegisteredModelWithVersion (
175179 modelName2 ,
176180 run . info . artifact_uri ,
@@ -192,6 +196,7 @@ describe('ModelManager', () => {
192196 expect ( latestModelVersion [ 0 ] . name ) . toBe ( modelName2 ) ;
193197 expect ( latestModelVersion [ 0 ] . tags [ 0 ] . key ) . toBe ( 'modelVersionTagKey' ) ;
194198 expect ( latestModelVersion [ 0 ] . tags [ 0 ] . value ) . toBe ( 'modelVersionTagValue' ) ;
199+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
195200 } ) ;
196201 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
197202 // Making it so console.error doesn't show up in the console
@@ -211,7 +216,7 @@ describe('ModelManager', () => {
211216
212217 describe ( 'setLatestModelVersionAlias' , ( ) => {
213218 test ( 'Should add an alias for the latest version of the specified registered model' , async ( ) => {
214- const modelName2 = `setLatestModelVersionAlias-test- model-${ timestamp } ` ;
219+ const modelName2 = `setLatestModelVersionAlias-model-${ timestamp } ` ;
215220 await modelManager . createRegisteredModelWithVersion (
216221 modelName2 ,
217222 run . info . artifact_uri ,
@@ -231,6 +236,7 @@ describe('ModelManager', () => {
231236 expect ( latestModelVersion [ 0 ] . version ) . toBe ( '2' ) ;
232237 expect ( latestModelVersion [ 0 ] . name ) . toBe ( modelName2 ) ;
233238 expect ( latestModelVersion [ 0 ] . aliases [ 0 ] ) . toBe ( 'modelVersionAlias' ) ;
239+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
234240 } ) ;
235241 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
236242 // Making it so console.error doesn't show up in the console
@@ -250,7 +256,7 @@ describe('ModelManager', () => {
250256
251257 describe ( 'updateLatestModelVersion' , ( ) => {
252258 test ( 'Should update the description of the latest model version' , async ( ) => {
253- const modelName2 = `updateLatestModelVersion-test- model-${ timestamp } ` ;
259+ const modelName2 = `updateLatestModelVersion-model-${ timestamp } ` ;
254260 await modelManager . createRegisteredModelWithVersion (
255261 modelName2 ,
256262 run . info . artifact_uri ,
@@ -269,6 +275,7 @@ describe('ModelManager', () => {
269275 expect ( latestModelVersion . version ) . toBe ( '2' ) ;
270276 expect ( latestModelVersion . name ) . toBe ( modelName2 ) ;
271277 expect ( latestModelVersion . description ) . toBe ( 'modelDescription' ) ;
278+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
272279 } ) ;
273280 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
274281 // Making it so console.error doesn't show up in the console
@@ -288,7 +295,7 @@ describe('ModelManager', () => {
288295
289296 describe ( 'updateAllModelVersion' , ( ) => {
290297 test ( "Should update the specified version's alias, tag, and description" , async ( ) => {
291- const modelName2 = `updateAllModelVersion-test- model-${ timestamp } ` ;
298+ const modelName2 = `updateAllModelVersion-model-${ timestamp } ` ;
292299 await modelManager . createRegisteredModelWithVersion (
293300 modelName2 ,
294301 run . info . artifact_uri ,
@@ -315,6 +322,7 @@ describe('ModelManager', () => {
315322 expect ( updatedModelVersionAll . description ) . toBe (
316323 'modelVersionDescription'
317324 ) ;
325+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
318326 } ) ;
319327 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
320328 // Making it so console.error doesn't show up in the console
@@ -334,7 +342,7 @@ describe('ModelManager', () => {
334342
335343 describe ( 'deleteLatestModelVersion' , ( ) => {
336344 test ( 'Should delete the latest version of the model' , async ( ) => {
337- const modelName2 = `deleteLatestModelVersion-test- model-${ timestamp } ` ;
345+ const modelName2 = `deleteLatestModelVersion-model-${ timestamp } ` ;
338346 await modelManager . createRegisteredModelWithVersion (
339347 modelName2 ,
340348 run . info . artifact_uri ,
@@ -349,6 +357,7 @@ describe('ModelManager', () => {
349357 const latestModelVersion : keyable =
350358 await modelRegistryClient . getLatestModelVersions ( modelName2 ) ;
351359 expect ( latestModelVersion [ 0 ] . version ) . toBe ( '1' ) ;
360+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
352361 } ) ;
353362 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
354363 // Making it so console.error doesn't show up in the console
@@ -374,7 +383,7 @@ describe('ModelManager', () => {
374383
375384 const runData : keyable = await runClient . getRun ( run . info . run_id ) ;
376385
377- const modelName2 = `createModelFromRunWithBestMetric-test- modelMax-${ timestamp } ` ;
386+ const modelName2 = `createModelFromRunWithBestMetric-modelMax-${ timestamp } ` ;
378387 await modelManager . createModelFromRunWithBestMetric (
379388 [ run . info . experiment_id ] ,
380389 runData . data . metrics [ 0 ] . key ,
@@ -387,6 +396,8 @@ describe('ModelManager', () => {
387396 expect ( maxModel . latest_versions [ 0 ] . source ) . toBe (
388397 runData . info . artifact_uri
389398 ) ;
399+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
400+ await runClient . deleteRun ( run2 . info . run_id ) ;
390401 } ) ;
391402
392403 test ( 'Should create model from run with best(minimum) metric' , async ( ) => {
@@ -396,7 +407,7 @@ describe('ModelManager', () => {
396407
397408 const runData2 : keyable = await runClient . getRun ( run2 . info . run_id ) ;
398409
399- const modelName2 = `createModelFromRunWithBestMetric-test- modelMin-${ timestamp } ` ;
410+ const modelName2 = `createModelFromRunWithBestMetric-modelMin-${ timestamp } ` ;
400411 await modelManager . createModelFromRunWithBestMetric (
401412 [ run2 . info . experiment_id ] ,
402413 runData2 . data . metrics [ 0 ] . key ,
@@ -409,6 +420,8 @@ describe('ModelManager', () => {
409420 expect ( minModel . latest_versions [ 0 ] . source ) . toBe (
410421 runData2 . info . artifact_uri
411422 ) ;
423+ await modelRegistryClient . deleteRegisteredModel ( modelName2 ) ;
424+ await runClient . deleteRun ( run2 . info . run_id ) ;
412425 } ) ;
413426
414427 test ( 'Should throw and console.error if no parameters are passed to the method' , async ( ) => {
@@ -426,4 +439,8 @@ describe('ModelManager', () => {
426439 consoleErrorMock . mockRestore ( ) ;
427440 } ) ;
428441 } ) ;
442+
443+ afterAll ( async ( ) => {
444+ await runClient . deleteRun ( run . info . run_id ) ;
445+ } ) ;
429446} ) ;
0 commit comments