diff options
Diffstat (limited to 'python/testSrc/com/jetbrains/env')
3 files changed, 102 insertions, 45 deletions
diff --git a/python/testSrc/com/jetbrains/env/python/PyPackagingTest.java b/python/testSrc/com/jetbrains/env/python/PyPackagingTest.java index 54afb702322b..8dcc2ec69f6f 100644 --- a/python/testSrc/com/jetbrains/env/python/PyPackagingTest.java +++ b/python/testSrc/com/jetbrains/env/python/PyPackagingTest.java @@ -43,7 +43,7 @@ public class PyPackagingTest extends PyEnvTestCase { final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.EMPTY_SDK); List<PyPackage> packages = null; try { - packages = ((PyPackageManagerImpl)PyPackageManager.getInstance(sdk)).getPackages(); + packages = PyPackageManager.getInstance(sdk).getPackages(false); } catch (PyExternalProcessException e) { final int retcode = e.getRetcode(); @@ -74,13 +74,13 @@ public class PyPackagingTest extends PyEnvTestCase { } final File tempDir = FileUtil.createTempDirectory(getTestName(false), null); final File venvDir = new File(tempDir, "venv"); - final String venvSdkHome = ((PyPackageManagerImpl)PyPackageManagerImpl.getInstance(sdk)).createVirtualEnv(venvDir.toString(), - false); + final String venvSdkHome = PyPackageManager.getInstance(sdk).createVirtualEnv(venvDir.toString(), + false); final Sdk venvSdk = createTempSdk(venvSdkHome, SdkCreationType.EMPTY_SDK); assertNotNull(venvSdk); assertTrue(PythonSdkType.isVirtualEnv(venvSdk)); assertInstanceOf(PythonSdkFlavor.getPlatformIndependentFlavor(venvSdk.getHomePath()), VirtualEnvSdkFlavor.class); - final List<PyPackage> packages = ((PyPackageManagerImpl)PyPackageManagerImpl.getInstance(venvSdk)).getPackages(); + final List<PyPackage> packages = PyPackageManager.getInstance(venvSdk).getPackages(false); final PyPackage setuptools = findPackage("setuptools", packages); assertNotNull(setuptools); assertEquals("setuptools", setuptools.getName()); @@ -109,15 +109,15 @@ public class PyPackagingTest extends PyEnvTestCase { try { final File tempDir = FileUtil.createTempDirectory(getTestName(false), null); final File venvDir = new File(tempDir, "venv"); - final String venvSdkHome = ((PyPackageManagerImpl)PyPackageManager.getInstance(sdk)).createVirtualEnv(venvDir.getPath(), false); + final String venvSdkHome = PyPackageManager.getInstance(sdk).createVirtualEnv(venvDir.getPath(), false); final Sdk venvSdk = createTempSdk(venvSdkHome, SdkCreationType.EMPTY_SDK); assertNotNull(venvSdk); - final PyPackageManagerImpl manager = (PyPackageManagerImpl)PyPackageManager.getInstance(venvSdk); - final List<PyPackage> packages1 = manager.getPackages(); + final PyPackageManager manager = PyPackageManager.getInstance(venvSdk); + final List<PyPackage> packages1 = manager.getPackages(false); // TODO: Install Markdown from a local file manager.install(list(PyRequirement.fromString("Markdown<2.2"), new PyRequirement("httplib2")), Collections.<String>emptyList()); - final List<PyPackage> packages2 = manager.getPackages(); + final List<PyPackage> packages2 = manager.getPackages(false); final PyPackage markdown2 = findPackage("Markdown", packages2); assertNotNull(markdown2); assertTrue(markdown2.isInstalled()); @@ -126,7 +126,7 @@ public class PyPackagingTest extends PyEnvTestCase { assertEquals("pip", pip1.getName()); assertEquals(PyPackageManagerImpl.PIP_VERSION, pip1.getVersion()); manager.uninstall(list(pip1)); - final List<PyPackage> packages3 = manager.getPackages(); + final List<PyPackage> packages3 = manager.getPackages(false); final PyPackage pip2 = findPackage("pip", packages3); assertNull(pip2); } diff --git a/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java b/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java index 4372715371eb..e29ab4cfdc8b 100644 --- a/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java +++ b/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java @@ -13,7 +13,7 @@ import com.jetbrains.python.console.pydev.PydevCompletionVariant; import com.jetbrains.python.debugger.PyDebuggerException; import com.jetbrains.python.debugger.PyExceptionBreakpointProperties; import com.jetbrains.python.debugger.PyExceptionBreakpointType; -import com.jetbrains.python.debugger.pydev.ProcessDebugger; +import com.jetbrains.python.debugger.pydev.PyDebugCallback; import com.jetbrains.python.sdk.flavors.PythonSdkFlavor; import java.util.List; @@ -52,8 +52,12 @@ public class PythonDebuggerTest extends PyEnvTestCase { }); } - public void testDebugger() { - runPythonTest(new PyUnitTestTask("", "test_debug.py") { + public void testPydevTests_Debugger() { + unittests("tests_python/test_debugger.py"); + } + + private void unittests(final String script) { + runPythonTest(new PyUnitTestTask("", script) { @Override protected String getTestDataPath() { return PythonHelpersLocator.getPythonCommunityPath() + "/helpers/pydev"; @@ -63,9 +67,18 @@ public class PythonDebuggerTest extends PyEnvTestCase { public void after() { allTestsPassed(); } + + @Override + protected int getTestTimeout() { + return 600000; + } }); } + public void testDebug() { //TODO: merge it into pydev tests + unittests("test_debug.py"); + } + public void testConditionalBreakpoint() throws Exception { runPythonTest(new PyDebuggerTask("/debug", "test1.py") { @Override @@ -128,7 +141,7 @@ public class PythonDebuggerTest extends PyEnvTestCase { } private void consoleExec(String command) { - myDebugProcess.consoleExec(command, new ProcessDebugger.DebugCallback<String>() { + myDebugProcess.consoleExec(command, new PyDebugCallback<String>() { @Override public void ok(String value) { diff --git a/python/testSrc/com/jetbrains/env/ut/PyUnitTestTask.java b/python/testSrc/com/jetbrains/env/ut/PyUnitTestTask.java index 01401ca1ca9a..550ca6690cfd 100644 --- a/python/testSrc/com/jetbrains/env/ut/PyUnitTestTask.java +++ b/python/testSrc/com/jetbrains/env/ut/PyUnitTestTask.java @@ -1,8 +1,11 @@ package com.jetbrains.env.ut; import com.google.common.collect.Lists; -import com.intellij.execution.*; +import com.intellij.execution.RunManager; +import com.intellij.execution.RunManagerEx; +import com.intellij.execution.RunnerAndConfigurationSettings; import com.intellij.execution.configurations.ConfigurationFactory; +import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.executors.DefaultRunExecutor; import com.intellij.execution.process.ProcessAdapter; import com.intellij.execution.process.ProcessEvent; @@ -29,20 +32,37 @@ import com.jetbrains.python.sdk.flavors.PythonSdkFlavor; import com.jetbrains.python.testing.AbstractPythonTestRunConfiguration; import com.jetbrains.python.testing.PythonTestConfigurationType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.junit.Assert; /** + * Tasks to run unit test configurations. + * You should extend it either implementing {@link #after()} and {@link #before()} or implement {@link #runTestOn(String)} + * yourself and use {@link #runConfiguration(com.intellij.execution.configurations.ConfigurationFactory, String, com.intellij.openapi.project.Project)} + * or {@link #runConfiguration(com.intellij.execution.RunnerAndConfigurationSettings, com.intellij.execution.configurations.RunConfiguration)} . + * Use {@link #myDescriptor} and {@link #myConsoleView} to check output + * * @author traff */ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask { protected ProcessHandler myProcessHandler; private boolean shouldPrintOutput = false; - private SMTestProxy.SMRootTestProxy myTestProxy; - private boolean mySetUp = false; - private SMTRunnerConsoleView myConsoleView; - private RunContentDescriptor myDescriptor; + /** + * Test root node + */ + protected SMTestProxy.SMRootTestProxy myTestProxy; + /** + * Output test console + */ + protected SMTRunnerConsoleView myConsoleView; + /** + * Test run descriptor + */ + protected RunContentDescriptor myDescriptor; + private StringBuilder myOutput; + private boolean mySetUp = false; public PyUnitTestTask() { } @@ -83,30 +103,30 @@ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask { @Override public void tearDown() throws Exception { UIUtil.invokeAndWaitIfNeeded(new Runnable() { - @Override - public void run() { - try { - if (mySetUp) { - if (myConsoleView != null) { - Disposer.dispose(myConsoleView); - myConsoleView = null; - } - if (myDescriptor != null) { - Disposer.dispose(myDescriptor); - myDescriptor = null; - } - - - PyUnitTestTask.super.tearDown(); - - mySetUp = false; - } - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - } + @Override + public void run() { + try { + if (mySetUp) { + if (myConsoleView != null) { + Disposer.dispose(myConsoleView); + myConsoleView = null; + } + if (myDescriptor != null) { + Disposer.dispose(myDescriptor); + myDescriptor = null; + } + + + PyUnitTestTask.super.tearDown(); + + mySetUp = false; + } + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + } ); } @@ -151,10 +171,30 @@ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask { } }.execute(); - final ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), settings).build(); + runConfiguration(settings, config); + } + + /** + * Run configuration. + * + * @param settings settings (if have any, null otherwise) + * @param config configuration to run + * @throws Exception + */ + protected void runConfiguration(@Nullable final RunnerAndConfigurationSettings settings, + @NotNull final RunConfiguration config) throws Exception { + final ExecutionEnvironment environment; + if (settings == null) { + environment = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), config).build(); + } + else { + environment = ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), settings).build(); + } //noinspection ConstantConditions + Assert.assertTrue(environment.getRunner().canRun(DefaultRunExecutor.EXECUTOR_ID, config)); + before(); final com.intellij.util.concurrency.Semaphore s = new com.intellij.util.concurrency.Semaphore(); @@ -177,7 +217,7 @@ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask { myOutput.append(event.getText()); } }); - myConsoleView = (com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView)descriptor.getExecutionConsole(); + myConsoleView = (SMTRunnerConsoleView)descriptor.getExecutionConsole(); myTestProxy = myConsoleView.getResultsViewer().getTestsRootNode(); myConsoleView.getResultsViewer().addEventsListener(new TestResultsViewer.SMEventsAdapter() { @Override @@ -194,7 +234,7 @@ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask { } }); - Assert.assertTrue(s.waitFor(60000)); + Assert.assertTrue(s.waitFor(getTestTimeout())); XDebuggerTestUtil.waitForSwing(); @@ -207,6 +247,10 @@ public abstract class PyUnitTestTask extends PyExecutionFixtureTestTask { disposeProcess(myProcessHandler); } + protected int getTestTimeout() { + return 60000; + } + protected void configure(AbstractPythonTestRunConfiguration config) { } |