11import { mainClassName } from "../../src/config" ;
2+ import { CodeContext } from "../../src/types/worker" ;
23import JobWorker from "../../src/worker" ;
4+ import fs from 'fs'
35
46describe ( "Python transform into executable" , ( ) => {
57 const functionName = "solution"
@@ -11,22 +13,22 @@ describe("Python transform into executable", () => {
1113} )
1214
1315
14- // TODO needs some work, cannot seem to ready file here, and is being recognized as success
15-
16- // describe("Python code excution test", ( ) => {
17- // it('should calculate a frequency in string' , () => {
18- // expect.assertions(1);
19-
20- // fs.readFile(`${__dirname}/../test-code/python/counter.py`, 'utf8', async (error, code) => {
21- // const codeContext: CodeContext = {
22- // code: code,
23- // functionName: "calculate"
24- // }
25- // const worker = new JobWorker("python3", codeContext);
26- // const response = await worker.startContainer()
27- // console.log(response)
28- // expect( response.codeOutput).toBe("Counter({'a': 2, 's': 2, 'w': 2, 'e': 2, 'l': 1, 'd': 1, 'k': 1})" )
29- // await worker.cleanupJob();
30- // } );
31- // })
32- // })
16+ describe ( "Python code excution test" , ( ) => {
17+ let code : string
18+ beforeAll ( ( done ) => {
19+ fs . readFile ( ` ${ __dirname } /../test-code/python/counter.py` , 'utf8' , ( err , data ) => {
20+ code = data
21+ done ( )
22+ } )
23+ } )
24+ it ( 'should calculate a frequency in string' , async ( ) => {
25+ const codeContext : CodeContext = {
26+ code : code ,
27+ functionName : "calculate"
28+ }
29+ const worker = new JobWorker ( "python3" , codeContext ) ;
30+ const response = await worker . startContainer ( )
31+ expect ( response . codeOutput ) . toBe ( "Counter({'a': 2, 's': 2, 'w': 2, 'e': 2, 'l': 1, 'd': 1, 'k': 1})" )
32+ await worker . cleanupJob ( ) ;
33+ } )
34+ } )
0 commit comments