MCPcopy Create free account
hub / github.com/wonderwhy-er/DesktopCommanderMCP / testPythonREPL

Function testPythonREPL

test/test-repl-interaction.js:67–138  ·  view source on GitHub ↗

* Test Python REPL interaction

()

Source from the content-addressed store, hash-verified

65 * Test Python REPL interaction
66 */
67async function testPythonREPL() {
68 console.log(`${colors.cyan}Running Python REPL interaction test...${colors.reset}`);
69
70 try {
71 // Setup Python test
72 // Find Python executable
73 const pythonCmd = process.platform === 'win32' ? 'python' : 'python3';
74
75 // Start a Python REPL process
76 const result = await terminalManager.executeCommand(pythonCmd + ' -i', 5000);
77
78 if (result.pid <= 0) {
79 throw new Error(`Failed to start Python REPL: ${result.output}`);
80 }
81
82 console.log(`${colors.green}✓ Started Python REPL with PID ${result.pid}${colors.reset}`);
83
84 // Wait for REPL to initialize
85 await sleep(1000);
86
87 // Send a command to the REPL with explicit Python print
88 const testValue = Math.floor(Math.random() * 100);
89 console.log(`${colors.blue}Test value: ${testValue}${colors.reset}`);
90
91 // Send two different commands to increase chances of seeing output
92 let success = terminalManager.sendInputToProcess(result.pid, `print("STARTING PYTHON TEST")\n`)
93 if (!success) {
94 throw new Error('Failed to send initial input to Python REPL');
95 }
96
97 // Wait a bit between commands
98 await sleep(1000);
99
100 // Send the actual test command
101 success = terminalManager.sendInputToProcess(result.pid, `print(f"REPL_TEST_VALUE: {${testValue} * 2}")\n`)
102 if (!success) {
103 throw new Error('Failed to send test input to Python REPL');
104 }
105
106 console.log(`${colors.green}✓ Sent test commands to Python REPL${colors.reset}`);
107
108 // Wait longer for the command to execute
109 await sleep(3000);
110
111 // Get output from the REPL
112 const output = terminalManager.getNewOutput(result.pid);
113 console.log(`Python REPL output: ${output || 'No output received'}`);
114
115 // Write output to file for inspection
116 await fs.writeFile(OUTPUT_FILE, `Python REPL output:\n${output || 'No output received'}`);
117
118 // Terminate the REPL process
119 const terminated = terminalManager.forceTerminate(result.pid);
120 if (!terminated) {
121 console.warn(`${colors.yellow}Warning: Could not terminate Python REPL process${colors.reset}`);
122 } else {
123 console.log(`${colors.green}✓ Terminated Python REPL process${colors.reset}`);
124 }

Callers 1

runTestsFunction · 0.85

Calls 6

logMethod · 0.80
executeCommandMethod · 0.80
sendInputToProcessMethod · 0.80
getNewOutputMethod · 0.80
forceTerminateMethod · 0.80
sleepFunction · 0.70

Tested by

no test coverage detected