From 7da229682a7d35c2053be668aec291582231a857 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 6 Aug 2015 14:37:06 +0300 Subject: [PATCH] fixed EDU-346 Ability to pass message to the 'passed' method --- .../fileTemplates/internal/test_helper.py.ft | 5 +++ .../fileTemplates/internal/test_helper.py.ft | 5 +++ .../learning/actions/StudyCheckAction.java | 8 ++-- .../edu/learning/run/StudySmartChecker.java | 2 +- .../edu/learning/run/StudyTestRunner.java | 37 ++++++++++++++++--- 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/python/edu/interactive-learning-intellij-py/resources/fileTemplates/internal/test_helper.py.ft b/python/edu/interactive-learning-intellij-py/resources/fileTemplates/internal/test_helper.py.ft index 78545a20a1b6..ca61ba52f459 100644 --- a/python/edu/interactive-learning-intellij-py/resources/fileTemplates/internal/test_helper.py.ft +++ b/python/edu/interactive-learning-intellij-py/resources/fileTemplates/internal/test_helper.py.ft @@ -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: diff --git a/python/edu/resources/fileTemplates/internal/test_helper.py.ft b/python/edu/resources/fileTemplates/internal/test_helper.py.ft index 196d2cc49478..d27866c23f01 100644 --- a/python/edu/resources/fileTemplates/internal/test_helper.py.ft +++ b/python/edu/resources/fileTemplates/internal/test_helper.py.ft @@ -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: diff --git a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java index 952a58c3b6fc..f170f468cf60 100644 --- a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java +++ b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/actions/StudyCheckAction.java @@ -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); } }); diff --git a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java index bf2b59999b11..69a605ce537f 100644 --- a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java +++ b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudySmartChecker.java @@ -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) { diff --git a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudyTestRunner.java b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudyTestRunner.java index 0fdd7a64408c..2a17d65d5b04 100644 --- a/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudyTestRunner.java +++ b/python/educational/interactive-learning/src/com/jetbrains/edu/learning/run/StudyTestRunner.java @@ -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; + } + } + }