From 00e6b440c5495ee454f6731385d9ee7517d5c7f0 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Fri, 25 Nov 2016 20:21:38 +0300 Subject: [PATCH] added option to skip running task file on check action --- .../edu/learning/checker/StudyCheckTask.java | 18 ++++++++++++++++-- .../fileTemplates/internal/test_helper.py.ft | 7 +++++++ .../edu/learning/PyStudyCheckAction.java | 14 -------------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckTask.java b/python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckTask.java index 53245182e16e..15cef49780fd 100644 --- a/python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckTask.java +++ b/python/educational-core/student/src/com/jetbrains/edu/learning/checker/StudyCheckTask.java @@ -3,6 +3,7 @@ package com.jetbrains.edu.learning.checker; import com.intellij.execution.process.CapturingProcessHandler; import com.intellij.execution.process.ProcessOutput; import com.intellij.ide.projectView.ProjectView; +import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; @@ -16,6 +17,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; import com.jetbrains.edu.learning.*; import com.jetbrains.edu.learning.actions.StudyAfterCheckAction; +import com.jetbrains.edu.learning.actions.StudyRunAction; import com.jetbrains.edu.learning.core.EduNames; import com.jetbrains.edu.learning.core.EduUtils; import com.jetbrains.edu.learning.courseFormat.*; @@ -38,7 +40,9 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun private final Ref myCheckInProcess; private final Process myTestProcess; private final String myCommandLine; + private boolean myRunTestFile = true; private static final String FAILED_CHECK_LAUNCH = "Failed to launch checking"; + private static final String DO_NOT_RUN_ON_CHECK = "DO_NOT_RUN_ON_CHECK"; public StudyCheckTask(Project project, StudyState studyState, Ref checkInProcess, Process testProcess, String commandLine) { super(project, "Checking Task"); @@ -87,7 +91,9 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun private void checkForEduCourse(@NotNull ProgressIndicator indicator) { final StudyTestsOutputParser.TestsOutput testsOutput = getTestOutput(indicator); - + if (myRunTestFile) { + ApplicationManager.getApplication().invokeLater(() -> runTask(myProject)); + } if (testsOutput != null) { if (testsOutput.isSuccess()) { onTaskSolved(testsOutput.getMessage()); @@ -103,6 +109,14 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun } } + private static void runTask(@NotNull Project project) { + final StudyRunAction runAction = (StudyRunAction)ActionManager.getInstance().getAction(StudyRunAction.ACTION_ID); + if (runAction == null) { + return; + } + runAction.run(project); + } + @Nullable private StudyTestsOutputParser.TestsOutput getTestOutput(@NotNull ProgressIndicator indicator) { final CapturingProcessHandler handler = new CapturingProcessHandler(myTestProcess, null, myCommandLine); @@ -111,7 +125,7 @@ public class StudyCheckTask extends com.intellij.openapi.progress.Task.Backgroun ApplicationManager.getApplication().invokeLater( () -> StudyCheckUtils.showTestResultPopUp("Check cancelled", MessageType.WARNING.getPopupBackground(), myProject)); } - + myRunTestFile = !output.getStdout().contains(DO_NOT_RUN_ON_CHECK); final Course course = StudyTaskManager.getInstance(myProject).getCourse(); if (course != null) { final StudyTestsOutputParser.TestsOutput testsOutput = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()); diff --git a/python/educational-python/resources/fileTemplates/internal/test_helper.py.ft b/python/educational-python/resources/fileTemplates/internal/test_helper.py.ft index 8dcb8f6458dd..7184ce0ab43d 100644 --- a/python/educational-python/resources/fileTemplates/internal/test_helper.py.ft +++ b/python/educational-python/resources/fileTemplates/internal/test_helper.py.ft @@ -248,6 +248,13 @@ def check_samples(samples=()): passed() +def do_not_run_on_check(): + """ + Do not execute task file on check + """ + print("#educational_plugin DO_NOT_RUN_ON_CHECK") + + def run_common_tests(error_text="Please, reload file and try again"): test_is_initial_text() test_is_not_empty() diff --git a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java index 52375b651e35..976e82b81d52 100644 --- a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java +++ b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyCheckAction.java @@ -1,7 +1,6 @@ package com.jetbrains.edu.learning; import com.intellij.execution.ExecutionException; -import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -11,7 +10,6 @@ import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.IdeFocusManager; import com.jetbrains.edu.learning.actions.StudyCheckAction; -import com.jetbrains.edu.learning.actions.StudyRunAction; import com.jetbrains.edu.learning.checker.StudyCheckTask; import com.jetbrains.edu.learning.checker.StudyCheckUtils; import com.jetbrains.edu.learning.checker.StudyTestRunner; @@ -44,9 +42,6 @@ public class PyStudyCheckAction extends StudyCheckAction { } if (StudyCheckUtils.hasBackgroundProcesses(project)) return; - final Course course = StudyTaskManager.getInstance(project).getCourse(); - if (course != null && !course.isAdaptive() && !runTask(project)) return; - final Task task = studyState.getTask(); final VirtualFile taskDir = studyState.getTaskDir(); StudyCheckUtils.flushWindows(task, taskDir); @@ -77,15 +72,6 @@ public class PyStudyCheckAction extends StudyCheckAction { })); } - private static boolean runTask(@NotNull Project project) { - final StudyRunAction runAction = (StudyRunAction)ActionManager.getInstance().getAction(StudyRunAction.ACTION_ID); - if (runAction == null) { - return false; - } - runAction.run(project); - return true; - } - @NotNull private StudyCheckTask getCheckTask(@NotNull final Project project, final StudyState studyState,