From f03ce9818bedc00eda664732e1efc7398af1096f Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 15 Dec 2017 03:52:36 +0300 Subject: [PATCH] Fix tests: move "testCantRerun" to UT only Its hard to check it with trial because for trial we use tempdir in tests and it fools rerun action to think testspect is set. Changing this may be hard, it does not make any sense nor does it affect production code. Leave it alone --- .../testing/PythonUnitTestingLikeTest.java | 56 ---------------- .../python/testing/PythonUnitTestingTest.java | 65 ++++++++++++++++++- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingLikeTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingLikeTest.java index fa396e3016b3..205ece00694f 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingLikeTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingLikeTest.java @@ -329,60 +329,4 @@ public abstract class PythonUnitTestingLikeTest("/testRunner/env/unit", "test_with_skips_and_errors.py", this::createTestRunner) { - - @Override - protected void checkTestResults(@NotNull final T runner, - @NotNull final String stdout, - @NotNull final String stderr, - @NotNull final String all) { - assert runner.getFailedTestsCount() > 0 : "We need failed tests to test broken rerun"; - - startMessagesCapture(); - - EdtTestUtil.runInEdtAndWait(() -> { - deleteAllTestFiles(myFixture); - runner.rerunFailedTests(); - }); - - final List throwables = getCapturesMessages().first; - Assert.assertThat("Exception shall be thrown", throwables, not(emptyCollectionOf(Throwable.class))); - final Throwable exception = throwables.get(0); - Assert.assertThat("ExecutionException should be thrown", exception, instanceOf(ExecutionException.class)); - Assert.assertThat("Wrong text", exception.getMessage(), equalTo(PyBundle.message("runcfg.tests.cant_rerun"))); - Assert.assertThat("No messages displayed for exception", getCapturesMessages().second, not(emptyCollectionOf(String.class))); - - - stopMessageCapture(); - } - }); - } - - /** - * Deletes all files in temp. folder - */ - private static void deleteAllTestFiles(@NotNull final CodeInsightTestFixture fixture) { - ApplicationManager.getApplication().runWriteAction(() -> { - final VirtualFile testRoot = fixture.getTempDirFixture().getFile("."); - assert testRoot != null : "No temp path?"; - try { - for (final VirtualFile child : testRoot.getChildren()) { - child.delete(null); - } - } - catch (final IOException e) { - throw new AssertionError(String.format("Failed to delete files in %s : %s", testRoot, e)); - } - }); - } } diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java index 55e6d319fc85..2315d394ee8a 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java @@ -15,19 +15,24 @@ */ package com.jetbrains.env.python.testing; +import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.RuntimeConfigurationWarning; import com.intellij.execution.testframework.sm.ServiceMessageBuilder; import com.intellij.execution.testframework.sm.runner.ui.MockPrinter; import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.testFramework.EdtTestUtil; +import com.intellij.testFramework.fixtures.CodeInsightTestFixture; import com.jetbrains.env.EnvTestTagsRequired; import com.jetbrains.env.PyExecutionFixtureTestTask; import com.jetbrains.env.ut.PyUnitTestProcessRunner; +import com.jetbrains.python.PyBundle; import com.jetbrains.python.PythonHelper; import com.jetbrains.python.console.PythonConsoleView; import com.jetbrains.python.psi.LanguageLevel; @@ -45,8 +50,7 @@ import java.util.Arrays; import java.util.List; import static com.jetbrains.env.ut.PyScriptTestProcessRunner.TEST_TARGET_PREFIX; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertEquals; /** @@ -69,6 +73,45 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest("/testRunner/env/unit", "test_with_skips_and_errors.py", + this::createTestRunner) { + + @Override + protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner, + @NotNull final String stdout, + @NotNull final String stderr, + @NotNull final String all) { + assert runner.getFailedTestsCount() > 0 : "We need failed tests to test broken rerun"; + + startMessagesCapture(); + + EdtTestUtil.runInEdtAndWait(() -> { + deleteAllTestFiles(myFixture); + runner.rerunFailedTests(); + }); + + final List throwables = getCapturesMessages().first; + Assert.assertThat("Exception shall be thrown", throwables, not(emptyCollectionOf(Throwable.class))); + final Throwable exception = throwables.get(0); + Assert.assertThat("ExecutionException should be thrown", exception, instanceOf(ExecutionException.class)); + Assert.assertThat("Wrong text", exception.getMessage(), equalTo(PyBundle.message("runcfg.tests.cant_rerun"))); + Assert.assertThat("No messages displayed for exception", getCapturesMessages().second, not(emptyCollectionOf(String.class))); + + + stopMessageCapture(); + } + }); + } + @Test public void testTcMessageEscaped() { final String[] messages = { @@ -765,4 +808,22 @@ public final class PythonUnitTestingTest extends PythonUnitTestingLikeTest { + final VirtualFile testRoot = fixture.getTempDirFixture().getFile("."); + assert testRoot != null : "No temp path?"; + try { + for (final VirtualFile child : testRoot.getChildren()) { + child.delete(null); + } + } + catch (final IOException e) { + throw new AssertionError(String.format("Failed to delete files in %s : %s", testRoot, e)); + } + }); + } }