mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Tests improved: configurations are no checked in more natural way
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# This does not work
|
||||
|
||||
|
||||
def spa<caret>m():
|
||||
"""
|
||||
|
||||
>>> 1 == 1
|
||||
> 1
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
-1
@@ -2,7 +2,6 @@
|
||||
|
||||
import aid.test.base
|
||||
|
||||
|
||||
class Th<caret>eTest(aid.test.base.TestBase):
|
||||
|
||||
def test_case_1(self):
|
||||
@@ -0,0 +1,12 @@
|
||||
# This does not work
|
||||
|
||||
import aid.test.base
|
||||
sp<caret>am=42
|
||||
|
||||
class TheTest(aid.test.base.TestBase):
|
||||
|
||||
def test_case_1(self):
|
||||
self.fail()
|
||||
|
||||
def test_case_2(self):
|
||||
pass
|
||||
+40
-37
@@ -15,21 +15,21 @@
|
||||
*/
|
||||
package com.jetbrains.env.python.testing;
|
||||
|
||||
import com.intellij.execution.RunnerAndConfigurationSettings;
|
||||
import com.intellij.execution.actions.ConfigurationContext;
|
||||
import com.intellij.execution.actions.ConfigurationFromContext;
|
||||
import com.intellij.execution.configurations.RunConfiguration;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.env.PyExecutionFixtureTestTask;
|
||||
import com.jetbrains.python.sdk.InvalidSdkException;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import com.jetbrains.python.testing.PythonTestLegacyConfigurationProducer;
|
||||
import com.jetbrains.python.testing.TestRunnerService;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
|
||||
/**
|
||||
@@ -40,54 +40,57 @@ import java.lang.reflect.InvocationTargetException;
|
||||
*/
|
||||
class CreateConfigurationTestTask extends PyExecutionFixtureTestTask {
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
private final String myTestRunnerName;
|
||||
@NotNull
|
||||
private final Class<? extends PythonTestLegacyConfigurationProducer> myProducer;
|
||||
private final String[] myFileNames;
|
||||
@NotNull
|
||||
private final Class<? extends RunConfiguration> myExpectedConfigurationType;
|
||||
|
||||
/**
|
||||
* @param producer class of configuration producer to check
|
||||
* @param testRunnerName test runner name (to set as default to make sure producer launched)
|
||||
* @param testRunnerName test runner name (to set as default to make sure producer launched)
|
||||
* @param expectedConfigurationType type configuration tha should be produced
|
||||
*/
|
||||
CreateConfigurationTestTask(@NotNull final Class<? extends PythonTestLegacyConfigurationProducer> producer,
|
||||
@NotNull final String testRunnerName) {
|
||||
CreateConfigurationTestTask(@NotNull final String testRunnerName,
|
||||
@NotNull final Class<? extends RunConfiguration> expectedConfigurationType) {
|
||||
this(testRunnerName, expectedConfigurationType, "test_file.py", "test_class.py");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param testRunnerName test runner name (to set as default to make sure producer launched) or null if set nothing
|
||||
* @param expectedConfigurationType type configuration tha should be produced
|
||||
* @param fileNames python files to check right click on
|
||||
*/
|
||||
CreateConfigurationTestTask(@Nullable final String testRunnerName,
|
||||
@NotNull final Class<? extends RunConfiguration> expectedConfigurationType,
|
||||
@NotNull final String... fileNames) {
|
||||
super("/testRunner/env/createConfigurationTest/");
|
||||
myProducer = producer;
|
||||
myTestRunnerName = testRunnerName;
|
||||
myFileNames = fileNames.clone();
|
||||
myExpectedConfigurationType = expectedConfigurationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTestOn(final String sdkHome) throws InvalidSdkException, IOException {
|
||||
// Set as default runner to check
|
||||
TestRunnerService.getInstance(myFixture.getModule()).setProjectConfiguration(myTestRunnerName);
|
||||
if (myTestRunnerName != null) {
|
||||
TestRunnerService.getInstance(myFixture.getModule()).setProjectConfiguration(myTestRunnerName);
|
||||
}
|
||||
|
||||
createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
myFixture.configureByFile("test.py");
|
||||
// Should create configuration from test class
|
||||
checkConfigurationCreatedFrom(myFixture.getElementAtCaret());
|
||||
// And from file
|
||||
checkConfigurationCreatedFrom(myFixture.getElementAtCaret().getContainingFile());
|
||||
|
||||
for (final String fileName : myFileNames) {
|
||||
myFixture.configureByFile(fileName);
|
||||
final RunnerAndConfigurationSettings runnerAndConfigurationSettings =
|
||||
new ConfigurationContext(myFixture.getElementAtCaret()).getConfiguration();
|
||||
Assert.assertNotNull("Producers were not able to create any configuration in " + fileName, runnerAndConfigurationSettings);
|
||||
final RunConfiguration configuration = runnerAndConfigurationSettings.getConfiguration();
|
||||
Assert.assertNotNull("No real configuration created", configuration);
|
||||
Assert.assertThat("No name for configuration", configuration.getName(), Matchers.not(Matchers.isEmptyOrNullString()));
|
||||
Assert.assertThat("Bad configuration type in " + fileName, configuration,
|
||||
Matchers.is(Matchers.instanceOf(myExpectedConfigurationType)));
|
||||
}
|
||||
}), ModalityState.NON_MODAL);
|
||||
}
|
||||
|
||||
|
||||
private void checkConfigurationCreatedFrom(@NotNull final PsiElement element) {
|
||||
|
||||
final PythonTestLegacyConfigurationProducer producer = createProducer();
|
||||
final ConfigurationFromContext context =
|
||||
producer.createConfigurationFromContext(new ConfigurationContext(element));
|
||||
Assert.assertNotNull(String.format("Failed to create context for %s", myTestRunnerName), context);
|
||||
Assert.assertNotNull(String.format("Configuration %s has not name", myTestRunnerName), context.getConfiguration().getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PythonTestLegacyConfigurationProducer createProducer() {
|
||||
try {
|
||||
return myProducer.getConstructor().newInstance();
|
||||
}
|
||||
catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new AssertionError(String.format("Failed to create instance of %s", myProducer), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.PyProcessWithConsoleTestTask;
|
||||
import com.jetbrains.env.ut.PyDocTestProcessRunner;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import com.jetbrains.python.testing.doctest.PythonDocTestRunConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -13,6 +14,14 @@ import static org.junit.Assert.assertEquals;
|
||||
* User : catherine
|
||||
*/
|
||||
public class PythonDocTestingTest extends PyEnvTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testConfigurationProducer() throws Exception {
|
||||
runPythonTest(
|
||||
new CreateConfigurationTestTask(null, PythonDocTestRunConfiguration.class, "doctest_test.py"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUTRunner() {
|
||||
runPythonTest(new PyProcessWithConsoleTestTask<PyDocTestProcessRunner>("/testRunner/env/doc", SdkCreationType.EMPTY_SDK) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.jetbrains.env.PyProcessWithConsoleTestTask;
|
||||
import com.jetbrains.env.ut.PyNoseTestProcessRunner;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import com.jetbrains.python.testing.PythonTestConfigurationsModel;
|
||||
import com.jetbrains.python.testing.nosetest.PythonNoseTestConfigurationProducer;
|
||||
import com.jetbrains.python.testing.universalTests.PyUniversalNoseTestConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class PythonNoseTestingTest extends PyEnvTestCase {
|
||||
@Test
|
||||
public void testConfigurationProducer() throws Exception {
|
||||
runPythonTest(
|
||||
new CreateConfigurationTestTask(PythonNoseTestConfigurationProducer.class, PythonTestConfigurationsModel.PYTHONS_NOSETEST_NAME));
|
||||
new CreateConfigurationTestTask(PythonTestConfigurationsModel.PYTHONS_NOSETEST_NAME, PyUniversalNoseTestConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.jetbrains.env.PyProcessWithConsoleTestTask;
|
||||
import com.jetbrains.env.ut.PyTestTestProcessRunner;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import com.jetbrains.python.testing.PythonTestConfigurationsModel;
|
||||
import com.jetbrains.python.testing.pytest.PyTestConfigurationProducer;
|
||||
import com.jetbrains.python.testing.universalTests.PyUniversalPyTestConfiguration;
|
||||
import com.jetbrains.python.testing.universalTests.TestTargetType;
|
||||
import org.hamcrest.Matchers;
|
||||
@@ -32,7 +31,7 @@ public class PythonPyTestingTest extends PyEnvTestCase {
|
||||
@Test
|
||||
public void testConfigurationProducer() throws Exception {
|
||||
runPythonTest(
|
||||
new CreateConfigurationTestTask(PyTestConfigurationProducer.class, PythonTestConfigurationsModel.PY_TEST_NAME));
|
||||
new CreateConfigurationTestTask(PythonTestConfigurationsModel.PY_TEST_NAME, PyUniversalPyTestConfiguration.class));
|
||||
}
|
||||
|
||||
// Import error should lead to test failure
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.jetbrains.env.ut.PyUnitTestProcessRunner;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.testing.PythonTestConfigurationsModel;
|
||||
import com.jetbrains.python.testing.unittest.PythonUnitTestConfigurationProducer;
|
||||
import com.jetbrains.python.testing.universalTests.PyUniversalUnitTestConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -46,8 +46,7 @@ public final class PythonUnitTestingTest extends PyEnvTestCase {
|
||||
|
||||
@Test
|
||||
public void testConfigurationProducer() throws Exception {
|
||||
runPythonTest(
|
||||
new CreateConfigurationTestTask(PythonUnitTestConfigurationProducer.class, PythonTestConfigurationsModel.PYTHONS_UNITTEST_NAME));
|
||||
new CreateConfigurationTestTask(PythonTestConfigurationsModel.PYTHONS_UNITTEST_NAME, PyUniversalUnitTestConfiguration.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user