use of com.jetbrains.python.debugger.PyDebugRunner in project intellij-community by JetBrains.
the class PyDebuggerTask method runTestOn.
public void runTestOn(String sdkHome) throws Exception {
final Project project = getProject();
final ConfigurationFactory factory = PythonConfigurationType.getInstance().getConfigurationFactories()[0];
final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", factory);
myRunConfiguration = (PythonRunConfiguration) settings.getConfiguration();
myRunConfiguration.setSdkHome(sdkHome);
myRunConfiguration.setScriptName(getScriptName());
myRunConfiguration.setWorkingDirectory(myFixture.getTempDirPath());
myRunConfiguration.setScriptParameters(getScriptParameters());
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
}
}.execute();
final PyDebugRunner runner = (PyDebugRunner) ProgramRunnerUtil.getRunner(getExecutorId(), settings);
Assert.assertTrue(runner.canRun(getExecutorId(), myRunConfiguration));
final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
final PythonCommandLineState pyState = (PythonCommandLineState) myRunConfiguration.getState(executor, env);
assert pyState != null;
pyState.setMultiprocessDebug(isMultiprocessDebug());
final ServerSocket serverSocket;
try {
//noinspection SocketOpenedButNotSafelyClosed
serverSocket = new ServerSocket(0);
} catch (IOException e) {
throw new ExecutionException("Failed to find free socket port", e);
}
final int serverLocalPort = serverSocket.getLocalPort();
final RunProfile profile = env.getRunProfile();
//turn off exception breakpoints by default
PythonDebuggerTest.createExceptionBreak(myFixture, false, false, false);
before();
setProcessCanTerminate(false);
myTerminateSemaphore = new Semaphore(0);
new WriteAction<ExecutionResult>() {
@Override
protected void run(@NotNull Result<ExecutionResult> result) throws Throwable {
myExecutionResult = pyState.execute(executor, runner.createCommandLinePatchers(myFixture.getProject(), pyState, profile, serverLocalPort));
mySession = XDebuggerManager.getInstance(getProject()).startSession(env, new XDebugProcessStarter() {
@NotNull
public XDebugProcess start(@NotNull final XDebugSession session) {
myDebugProcess = new PyDebugProcess(session, serverSocket, myExecutionResult.getExecutionConsole(), myExecutionResult.getProcessHandler(), isMultiprocessDebug());
StringBuilder output = new StringBuilder();
myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
output.append(event.getText());
}
@Override
public void processTerminated(ProcessEvent event) {
myTerminateSemaphore.release();
if (event.getExitCode() != 0 && !myProcessCanTerminate) {
Assert.fail("Process terminated unexpectedly\n" + output.toString());
}
}
});
myDebugProcess.getProcessHandler().startNotify();
return myDebugProcess;
}
});
result.setResult(myExecutionResult);
}
}.execute().getResultObject();
OutputPrinter myOutputPrinter = null;
if (shouldPrintOutput) {
myOutputPrinter = new OutputPrinter();
myOutputPrinter.start();
}
myPausedSemaphore = new Semaphore(0);
mySession.addSessionListener(new XDebugSessionListener() {
@Override
public void sessionPaused() {
if (myPausedSemaphore != null) {
myPausedSemaphore.release();
}
}
});
doTest(myOutputPrinter);
}
Aggregations