mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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
This commit is contained in:
-56
@@ -329,60 +329,4 @@ public abstract class PythonUnitTestingLikeTest<T extends PyScriptTestProcessRun
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run tests, delete file and click "rerun" should throw exception and display error since test ids do not point to correct PSI
|
||||
* from that moment
|
||||
*/
|
||||
@Test
|
||||
public void testCantRerun() throws Exception {
|
||||
startMessagesCapture();
|
||||
|
||||
runPythonTest(
|
||||
new PyUnitTestLikeProcessWithConsoleTestTask<T>("/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<Throwable> 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+63
-2
@@ -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<PyUni
|
||||
new ConfigurationTarget("foo.bar", TestTargetType.PYTHON).checkValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run tests, delete file and click "rerun" should throw exception and display error since test ids do not point to correct PSI
|
||||
* from that moment
|
||||
*/
|
||||
@Test
|
||||
public void testCantRerun() {
|
||||
startMessagesCapture();
|
||||
|
||||
runPythonTest(
|
||||
new PyUnitTestLikeProcessWithConsoleTestTask<PyUnitTestProcessRunner>("/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<Throwable> 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<PyUni
|
||||
super(relativePathToTestData, scriptName, rerunFailedTests, PythonUnitTestingTest.this::createTestRunner);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user