mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed EDU-346 Ability to pass message to the 'passed' method
This commit is contained in:
+5
@@ -137,6 +137,11 @@ def test_answer_placeholders_text_deleted(error_text="Don't just delete task tex
|
||||
passed()
|
||||
|
||||
|
||||
def set_congratulation_message(message):
|
||||
""" Overrides default 'Congratulations!' message """
|
||||
print("#educational_plugin CONGRATS_MESSAGE " + message)
|
||||
|
||||
|
||||
def failed(message="Please, reload the task and try again.", name=None):
|
||||
""" Reports failure """
|
||||
if not name:
|
||||
|
||||
@@ -137,6 +137,11 @@ def test_answer_placeholders_text_deleted(error_text="Don't just delete task tex
|
||||
passed()
|
||||
|
||||
|
||||
def set_congratulation_message(message):
|
||||
""" Overrides default 'Congratulations!' message """
|
||||
print("#educational_plugin CONGRATS_MESSAGE " + message)
|
||||
|
||||
|
||||
def failed(message="Please, reload the task and try again.", name=None):
|
||||
""" Reports failure """
|
||||
if not name:
|
||||
|
||||
+4
-4
@@ -223,18 +223,18 @@ public class StudyCheckAction extends DumbAwareAction {
|
||||
});
|
||||
return;
|
||||
}
|
||||
final String failedMessage = testRunner.getTestsOutput(output);
|
||||
final StudyTestRunner.TestsOutput testsOutput = testRunner.getTestsOutput(output);
|
||||
final StudySettings studySettings = StudySettings.getInstance();
|
||||
|
||||
final String login = studySettings.getLogin();
|
||||
final String password = StringUtil.isEmptyOrSpaces(login) ? "" : studySettings.getPassword();
|
||||
if (StudyTestRunner.TEST_OK.equals(failedMessage)) {
|
||||
if (testsOutput.isSuccess()) {
|
||||
taskManager.setStatus(task, StudyStatus.Solved);
|
||||
EduStepicConnector.postAttempt(task, true, login, password);
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showTestResultPopUp("Congratulations!", MessageType.INFO.getPopupBackground(), project);
|
||||
showTestResultPopUp(testsOutput.getMessage(), MessageType.INFO.getPopupBackground(), project);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -264,7 +264,7 @@ public class StudyCheckAction extends DumbAwareAction {
|
||||
}
|
||||
});
|
||||
}
|
||||
showTestResultPopUp(failedMessage, MessageType.ERROR.getPopupBackground(), project);
|
||||
showTestResultPopUp(testsOutput.getMessage(), MessageType.ERROR.getPopupBackground(), project);
|
||||
navigateToFailedPlaceholder(studyState, task, taskDir, project);
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public class StudySmartChecker {
|
||||
Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
|
||||
final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess);
|
||||
final ProcessOutput output = handler.runProcess();
|
||||
boolean res = testRunner.getTestsOutput(output).equals(StudyTestRunner.TEST_OK);
|
||||
boolean res = testRunner.getTestsOutput(output).isSuccess();
|
||||
StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
|
||||
StudyUtils.deleteFile(windowCopy);
|
||||
if (fileWindows != null) {
|
||||
|
||||
+32
-5
@@ -11,6 +11,7 @@ public abstract class StudyTestRunner {
|
||||
private static final String ourStudyPrefix = "#educational_plugin";
|
||||
public static final String TEST_OK = "test OK";
|
||||
private static final String TEST_FAILED = "FAILED + ";
|
||||
private static final String CONGRATS_MESSAGE = "CONGRATS_MESSAGE ";
|
||||
protected final Task myTask;
|
||||
protected final VirtualFile myTaskDir;
|
||||
|
||||
@@ -22,17 +23,43 @@ public abstract class StudyTestRunner {
|
||||
public abstract Process createCheckProcess(@NotNull final Project project, @NotNull final String executablePath) throws ExecutionException;
|
||||
|
||||
@NotNull
|
||||
public String getTestsOutput(@NotNull final ProcessOutput processOutput) {
|
||||
public TestsOutput getTestsOutput(@NotNull final ProcessOutput processOutput) {
|
||||
String congratulations = "Congratulations!";
|
||||
for (String line : processOutput.getStdoutLines()) {
|
||||
if (line.contains(ourStudyPrefix)) {
|
||||
if (line.startsWith(ourStudyPrefix)) {
|
||||
if (line.contains(TEST_OK)) {
|
||||
continue;
|
||||
}
|
||||
int messageStart = line.indexOf(TEST_FAILED);
|
||||
return line.substring(messageStart + TEST_FAILED.length());
|
||||
|
||||
if (line.contains(CONGRATS_MESSAGE)) {
|
||||
congratulations = line.substring(line.indexOf(CONGRATS_MESSAGE) + CONGRATS_MESSAGE.length());
|
||||
}
|
||||
|
||||
if (line.contains(TEST_FAILED)) {
|
||||
return new TestsOutput(false, line.substring(line.indexOf(TEST_FAILED) + TEST_FAILED.length()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_OK;
|
||||
return new TestsOutput(true, congratulations);
|
||||
}
|
||||
|
||||
public static class TestsOutput {
|
||||
private final boolean isSuccess;
|
||||
private final String myMessage;
|
||||
|
||||
public TestsOutput(boolean isSuccess, @NotNull final String message) {
|
||||
this.isSuccess = isSuccess;
|
||||
myMessage = message;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return myMessage;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user