33 * Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { expect } from '@playwright/test' ;
76import { Application } from '../../../infra/index.js' ;
7+ import { expect } from '../../_test.setup.js' ;
88
99export const RETICULATE_SESSION = 'Python (reticulate)' ;
1010
@@ -18,50 +18,42 @@ export async function verifyReticulateFunctionality(
1818 const { console, sessions, variables } = app . workbench ;
1919
2020 // Create a variable x in Python session
21- await sessions . select ( pythonSessionId , true ) ;
22- await runCodeExpectVariable ( app , `x=${ xValue } ` , { name : 'x' , value : xValue } ) ;
21+ await expect ( async ( ) => {
22+ await console . executeCode ( 'Python' , `x = ${ xValue } ` ) ;
23+ await variables . expectVariableToBe ( 'x' , xValue , 2000 ) ;
24+ } , 'Can create variable in Python session' ) . toPass ( ) ;
2325
2426 // Switch to the R session and create an R variable `y` by accessing the Python
2527 // variable `x` through reticulate.
26- await console . clearButton . click ( ) ;
27- await sessions . select ( rSessionId ) ;
28- await runCodeExpectVariable ( app , 'y<-reticulate::py$x' , { name : 'y' , value : xValue } ) ;
28+ await expect ( async ( ) => {
29+ await console . executeCode ( 'R' , 'y<-reticulate::py$x' ) ;
30+ await variables . expectVariableToBe ( 'y' , xValue , 2000 ) ;
31+ } , 'Can access Python variable x from R' ) . toPass ( ) ;
2932
3033 // Clear the console again and re-check to ensure the R-side variable persists.
3134 await console . clearButton . click ( ) ;
3235 await variables . expectVariableToBe ( 'y' , xValue ) ;
3336
3437 // Verify able to overwrite the R variable `y` with an integer literal on the R side.
35- await runCodeExpectVariable ( app , `y <- ${ yValue } L` , { name : 'y' , value : yValue } ) ;
38+ await expect ( async ( ) => {
39+ await console . executeCode ( 'R' , `y <- ${ yValue } L` ) ;
40+ await variables . expectVariableToBe ( 'y' , yValue , 2000 ) ;
41+ } , 'Can overwrite the R variable' ) . toPass ( ) ;
3642
3743 // Verify executing reticulate::repl_python() moves focus to the reticulate session
3844 await console . pasteCodeToConsole ( `reticulate::repl_python(input = "z = ${ zValue } ")` , true ) ;
3945 await sessions . expectSessionPickerToBe ( pythonSessionId , 20000 ) ;
4046 await console . clearButton . click ( ) ;
4147
4248 // Print the R variable r.y (should reflect the R-side value) and ensure it appears in the console
43- await runCodeExpectOutput ( app , 'print(r.y)' , yValue ) ;
44-
45- // Print the Python variable z (created via repl_python) and ensure it appears as well
46- await runCodeExpectOutput ( app , 'print(z)' , zValue ) ;
47- }
48-
49- async function runCodeExpectVariable ( app : Application , code : string , variable : { name : string ; value : string } = { name : '' , value : '' } ) {
50- const { console, variables } = app . workbench ;
51-
5249 await expect ( async ( ) => {
53- await console . sendInterrupt ( ) ;
54- await console . pasteCodeToConsole ( code , true ) ;
55- await variables . expectVariableToBe ( variable . name , variable . value , 2000 ) ;
56- } , 'Run code and wait for variable to be present' ) . toPass ( { timeout : 10000 } ) ;
57- }
58-
59- async function runCodeExpectOutput ( app : Application , commmand : string , value : string ) {
60- const { console } = app . workbench ;
50+ await console . executeCode ( 'Python' , 'print(r.y)' ) ;
51+ await console . waitForConsoleContents ( yValue , { timeout : 5000 } ) ;
52+ } , 'Can print the R variable r.y from Python' ) . toPass ( ) ;
6153
54+ // Print the Python variable z (created via repl_python) and ensure it appears as well
6255 await expect ( async ( ) => {
63- await console . sendInterrupt ( ) ;
64- await console . pasteCodeToConsole ( commmand , true ) ;
65- await console . waitForConsoleContents ( value , { timeout : 2000 } ) ;
66- } , 'Run code and expect console output' ) . toPass ( { timeout : 10000 } ) ;
56+ await console . executeCode ( 'Python' , 'print(z)' ) ;
57+ await console . waitForConsoleContents ( zValue , { timeout : 5000 } ) ;
58+ } , 'Can print the Python variable z from Python' ) . toPass ( ) ;
6759}
0 commit comments