mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Env tests moved to community.
This commit is contained in:
@@ -3,7 +3,7 @@ __author__ = 'Dmitry.Trofimov'
|
||||
import unittest
|
||||
import os
|
||||
|
||||
test_data_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..', '..', 'python', 'testData', 'debug'))
|
||||
test_data_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'testData', 'debug'))
|
||||
|
||||
class PyDevTestCase(unittest.TestCase):
|
||||
def testZipFileExits(self):
|
||||
|
||||
1
python/testData/__init__.py
Normal file
1
python/testData/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'traff'
|
||||
BIN
python/testData/debug/Adder-0.1.egg
Normal file
BIN
python/testData/debug/Adder-0.1.egg
Normal file
Binary file not shown.
8
python/testData/debug/Test_Resume.py
Normal file
8
python/testData/debug/Test_Resume.py
Normal file
@@ -0,0 +1,8 @@
|
||||
def foo(x):
|
||||
print(x)
|
||||
|
||||
foo(1)
|
||||
foo(2)
|
||||
|
||||
|
||||
|
||||
1
python/testData/debug/__init__.py
Normal file
1
python/testData/debug/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'traff'
|
||||
BIN
python/testData/debug/pycharm-debug.egg
Normal file
BIN
python/testData/debug/pycharm-debug.egg
Normal file
Binary file not shown.
5
python/testData/debug/test1.py
Normal file
5
python/testData/debug/test1.py
Normal file
@@ -0,0 +1,5 @@
|
||||
i = 0
|
||||
while True:
|
||||
print(i)
|
||||
i = i + 1
|
||||
|
||||
8
python/testData/debug/test2.py
Normal file
8
python/testData/debug/test2.py
Normal file
@@ -0,0 +1,8 @@
|
||||
def foo(x):
|
||||
y = x + 2
|
||||
print(y)
|
||||
|
||||
z = 1
|
||||
foo(z)
|
||||
z += 1
|
||||
print(z)
|
||||
26
python/testData/debug/test3.py
Normal file
26
python/testData/debug/test3.py
Normal file
@@ -0,0 +1,26 @@
|
||||
class A:
|
||||
def __init__(self, z):
|
||||
self.z = z
|
||||
|
||||
def foo(self, x):
|
||||
y = 2 * x + self.z
|
||||
return 1 + y
|
||||
|
||||
|
||||
def zoo(x):
|
||||
y = int((x - 2) / (x - 1))
|
||||
|
||||
return A(y)
|
||||
|
||||
print(zoo(2).foo(2))
|
||||
|
||||
try:
|
||||
try:
|
||||
print(zoo(1).foo(2)) #we got ZeroDivision here
|
||||
finally:
|
||||
print(zoo(0).foo(2))
|
||||
except:
|
||||
pass
|
||||
|
||||
a = zoo(-1)
|
||||
print(a.foo(2))
|
||||
5
python/testData/debug/test4.py
Normal file
5
python/testData/debug/test4.py
Normal file
@@ -0,0 +1,5 @@
|
||||
xval = 0
|
||||
xvalue1 = 1
|
||||
xvalue2 = 2
|
||||
print(xvalue1 + xvalue2)
|
||||
|
||||
16
python/testData/debug/test_continuation.py
Normal file
16
python/testData/debug/test_continuation.py
Normal file
@@ -0,0 +1,16 @@
|
||||
class Boo:
|
||||
def bu(self, y):
|
||||
return 1 + y
|
||||
|
||||
|
||||
class Foo:
|
||||
def fu(self):
|
||||
return Boo()
|
||||
|
||||
x = 0
|
||||
print(x)
|
||||
x = Foo().fu()\
|
||||
.bu(x)
|
||||
print(x)
|
||||
x=2
|
||||
print(x)
|
||||
8
python/testData/debug/test_continuation2.py
Normal file
8
python/testData/debug/test_continuation2.py
Normal file
@@ -0,0 +1,8 @@
|
||||
x = 0
|
||||
print(x)
|
||||
x = 1+\
|
||||
2+\
|
||||
3
|
||||
print(x)
|
||||
x=2
|
||||
print(x)
|
||||
4
python/testData/debug/test_egg.py
Normal file
4
python/testData/debug/test_egg.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from adder import adder
|
||||
|
||||
x = adder.add(7, 9)
|
||||
print(x)
|
||||
8
python/testData/debug/test_exceptbreak.py
Normal file
8
python/testData/debug/test_exceptbreak.py
Normal file
@@ -0,0 +1,8 @@
|
||||
def foo(x):
|
||||
return 1/x
|
||||
|
||||
def zoo(x):
|
||||
res = foo(x)
|
||||
return res
|
||||
|
||||
print(zoo(0))
|
||||
7
python/testData/debug/test_input.py
Normal file
7
python/testData/debug/test_input.py
Normal file
@@ -0,0 +1,7 @@
|
||||
while True:
|
||||
promt = "print command > "
|
||||
try:
|
||||
string = raw_input(promt)
|
||||
except :
|
||||
string = input(promt)
|
||||
print ("command was " + string)
|
||||
13
python/testData/debug/test_multiprocess.py
Normal file
13
python/testData/debug/test_multiprocess.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from concurrent.futures import ProcessPoolExecutor
|
||||
def my_foo(arg_):
|
||||
return arg_
|
||||
|
||||
def main():
|
||||
arg = ['Result:OK']
|
||||
with ProcessPoolExecutor(1) as exec:
|
||||
result = exec.map(my_foo, arg)
|
||||
for i in result:
|
||||
print(i)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
24
python/testData/debug/test_multithread.py
Normal file
24
python/testData/debug/test_multithread.py
Normal file
@@ -0,0 +1,24 @@
|
||||
try:
|
||||
import thread
|
||||
except :
|
||||
import _thread as thread
|
||||
|
||||
import threading
|
||||
|
||||
def bar(y):
|
||||
z = 100 + y
|
||||
print("Z=%d"%z)
|
||||
|
||||
def foo(x):
|
||||
y = x + 1
|
||||
print("Y=%d"%y)
|
||||
|
||||
t = threading.Thread(target=bar, args=(y,))
|
||||
t.start()
|
||||
|
||||
|
||||
id = thread.start_new_thread(foo, (1,))
|
||||
|
||||
while True:
|
||||
pass
|
||||
|
||||
19
python/testData/debug/test_remote.py
Normal file
19
python/testData/debug/test_remote.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
sys.stderr.write("Not enough arguments")
|
||||
sys.exit(1)
|
||||
|
||||
port = int(sys.argv[1])
|
||||
|
||||
x = 0
|
||||
|
||||
from pydev import pydevd
|
||||
pydevd.settrace('localhost', port=port, stdoutToServer=True, stderrToServer=True)
|
||||
|
||||
x = 1
|
||||
x = 2
|
||||
x = 3
|
||||
|
||||
print("OK")
|
||||
8
python/testData/debug/test_runtoline.py
Normal file
8
python/testData/debug/test_runtoline.py
Normal file
@@ -0,0 +1,8 @@
|
||||
x = 0
|
||||
print(x)
|
||||
while x<2:
|
||||
x+=1
|
||||
print(x)
|
||||
|
||||
x+=10
|
||||
print("x = %d" % x)
|
||||
4
python/testData/debug/test_stepOverCondition.py
Normal file
4
python/testData/debug/test_stepOverCondition.py
Normal file
@@ -0,0 +1,4 @@
|
||||
x = 1
|
||||
y = 2
|
||||
y = x + y
|
||||
print(y)
|
||||
BIN
python/testData/debug/zipped_lib.zip
Normal file
BIN
python/testData/debug/zipped_lib.zip
Normal file
Binary file not shown.
@@ -16,7 +16,7 @@ import com.intellij.testFramework.fixtures.impl.ModuleFixtureBuilderImpl;
|
||||
import com.intellij.testFramework.fixtures.impl.ModuleFixtureImpl;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.python.PythonModuleTypeBase;
|
||||
import com.jetbrains.python.fixtures.PyProfessionalTestCase;
|
||||
import com.jetbrains.python.PythonTestUtil;
|
||||
import com.jetbrains.python.sdk.InvalidSdkException;
|
||||
import com.jetbrains.python.sdkTools.PyTestSdkTools;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
@@ -83,7 +83,7 @@ public abstract class PyExecutionFixtureTestTask extends PyTestTask {
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return PyProfessionalTestCase.getProfessionalTestDataPath();
|
||||
return PythonTestUtil.getTestDataPath();
|
||||
}
|
||||
|
||||
protected void initFixtureBuilder() {
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.django.facet.DjangoFacet;
|
||||
import com.jetbrains.django.fixtures.DjangoTestCase;
|
||||
import com.jetbrains.env.python.debug.PyDebuggerTask;
|
||||
import com.jetbrains.python.fixtures.PyProfessionalTestCase;
|
||||
import com.jetbrains.python.templateLanguages.TemplatesService;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class DjangoEnvTestTask extends PyDebuggerTask {
|
||||
|
||||
protected final int myPort;
|
||||
|
||||
protected String getTestDataPath() {
|
||||
return PyProfessionalTestCase.getProfessionalTestDataPath() + "/django/debug";
|
||||
}
|
||||
|
||||
public DjangoEnvTestTask(String workingFolder, String scriptName, String scriptParameters, int port) {
|
||||
setWorkingFolder(getTestDataPath() + workingFolder);
|
||||
setScriptName(scriptName);
|
||||
setScriptParameters(scriptParameters + port);
|
||||
myPort = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp(String testName) throws Exception {
|
||||
super.setUp(testName);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
Module module = myFixture.getModule();
|
||||
if (module != null && !DjangoFacet.isPresent(module)) {
|
||||
DjangoTestCase.addDjangoFacet(module);
|
||||
TemplatesService.getInstance(module).setTemplateLanguage(TemplatesService.DJANGO);
|
||||
}
|
||||
TemplatesService.getInstance(module).setTemplateLanguage(TemplatesService.DJANGO);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
TemplatesService.getInstance(myFixture.getModule()).setTemplateLanguage(TemplatesService.NONE);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public static void checkModuleForFile(Project project, VirtualFile vFile) {
|
||||
Module module = ModuleUtil.findModuleForFile(vFile, project);
|
||||
Assert.assertNotNull(module); //should be in our module for correct breakpoints setting
|
||||
Assert.assertTrue(DjangoFacet.isPresent(module));
|
||||
}
|
||||
|
||||
static class Response {
|
||||
private final String content;
|
||||
|
||||
|
||||
public Response(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void contains(String string) {
|
||||
Assert.assertTrue("Cant find '" + string + "' in content: \n" + content, content.contains(string));
|
||||
}
|
||||
|
||||
public static Response load(String address) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
// Send data
|
||||
URL url = new URL(address);
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setDoOutput(true);
|
||||
conn.setConnectTimeout(0);
|
||||
conn.setReadTimeout(0);
|
||||
conn.setUseCaches(false);
|
||||
|
||||
// Get the response
|
||||
Scanner s = new Scanner(conn.getInputStream());
|
||||
|
||||
|
||||
while (s.hasNextLine()) {
|
||||
String line = s.nextLine();
|
||||
sb.append(line + "\n");
|
||||
// Process line...
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
sb = new StringBuilder(e.getMessage());
|
||||
}
|
||||
return new Response(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected static LoadingPage loadPage(final String url) {
|
||||
final Ref<DjangoEnvTestTask.Response> response = Ref.create(null);
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
response.set(Response.load("http://127.0.0.1:" + url));
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
return new LoadingPage(thread, response);
|
||||
}
|
||||
|
||||
protected static class LoadingPage {
|
||||
private Thread myThread;
|
||||
private Ref<Response> myResponse;
|
||||
|
||||
public LoadingPage(Thread thread, Ref<Response> response) {
|
||||
myThread = thread;
|
||||
myResponse = response;
|
||||
}
|
||||
|
||||
public void join() throws InterruptedException {
|
||||
myThread.join();
|
||||
}
|
||||
|
||||
public Response get() throws InterruptedException {
|
||||
join();
|
||||
return myResponse.get();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTags() {
|
||||
return ImmutableSet.of("django");
|
||||
}
|
||||
|
||||
protected void waitForStart() throws InterruptedException {
|
||||
waitForOutput("Development server is running", "Starting development server");
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.jetbrains.django.actions.manage.ManageTaskActions;
|
||||
import com.jetbrains.django.manage.BaseCommand;
|
||||
import com.jetbrains.django.testRunner.DjangoTestsConfigurationType;
|
||||
import com.jetbrains.django.util.DjangoUtil;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Ilya.Kazakevich
|
||||
*/
|
||||
public class DjangoManageTaskActionsTest extends PyEnvTestCase {
|
||||
|
||||
/**
|
||||
* Checks that "manage.py" UI displays correct commands
|
||||
*/
|
||||
public void testManageCommands() throws Exception {
|
||||
runPythonTest(new DjangoManageCommandsTestTask());
|
||||
}
|
||||
|
||||
|
||||
private static class DjangoManageCommandsTestTask extends DjangoPathTestTask {
|
||||
@Nullable
|
||||
@Override
|
||||
public ConfigurationFactory getFactory() {
|
||||
return DjangoTestsConfigurationType.getInstance().getConfigurationFactories()[0];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void configure(final AbstractPythonRunConfiguration config) throws IOException {
|
||||
super.configure(config);
|
||||
final Module module = config.getModule();
|
||||
assert module != null : "Config has no module";
|
||||
ModuleRootModificationUtil.setModuleSdk(module, config.getSdk());
|
||||
|
||||
|
||||
Assert.assertNotNull("Django not found", DjangoUtil.getDjangoPath(config.getSdk()));
|
||||
|
||||
final Collection<String> expectedCommands = new HashSet<String>();
|
||||
expectedCommands.add("runserver");
|
||||
expectedCommands.add("dbshell");
|
||||
expectedCommands.add("syncdb");
|
||||
if (DjangoUtil.isDjangoVersionAtLeast(myFixture.getModule(), 7)) {
|
||||
expectedCommands.add("makemigrations");
|
||||
expectedCommands.add("migrate");
|
||||
}
|
||||
|
||||
final List<BaseCommand> commands = ManageTaskActions.getInstance().getCommands(myFixture.getModule());
|
||||
|
||||
for (final BaseCommand command : commands) {
|
||||
expectedCommands.remove(command.getCommand());
|
||||
}
|
||||
Assert.assertTrue(String.format("Commands '%s' were not found between %s", expectedCommands, commands), expectedCommands.isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.execution.executors.DefaultRunExecutor;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.ProgramRunner;
|
||||
import com.intellij.execution.ui.ExecutionConsole;
|
||||
import com.intellij.execution.ui.RunContentDescriptor;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.xdebugger.XDebuggerTestUtil;
|
||||
import com.jetbrains.django.facet.DjangoFacet;
|
||||
import com.jetbrains.django.fixtures.DjangoTestCase;
|
||||
import com.jetbrains.django.manage.DjangoManageTask;
|
||||
import com.jetbrains.django.testRunner.DjangoTestsConfigurationType;
|
||||
import com.jetbrains.django.ui.DjangoBundle;
|
||||
import com.jetbrains.env.PyExecutionFixtureTestTask;
|
||||
import com.jetbrains.python.PythonHelpersLocator;
|
||||
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
|
||||
import com.jetbrains.python.run.PythonTracebackFilter;
|
||||
import com.jetbrains.python.sdk.InvalidSdkException;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import com.jetbrains.python.templateLanguages.TemplatesService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public abstract class DjangoManageTestTask extends PyExecutionFixtureTestTask {
|
||||
private StringBuilder myOutput;
|
||||
private StringBuilder myStdErr;
|
||||
private StringBuilder myStdOut;
|
||||
|
||||
private RunContentDescriptor myDescriptor;
|
||||
private ProcessHandler myProcessHandler;
|
||||
private ExecutionConsole myConsoleView;
|
||||
private Sdk mySdk;
|
||||
private RunContentExecutor myRunContentExecutor;
|
||||
|
||||
@Override
|
||||
protected abstract String getTestDataPath();
|
||||
|
||||
@Override
|
||||
public void setUp(String testName) throws Exception {
|
||||
super.setUp(testName);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
Module module = myFixture.getModule();
|
||||
if (module != null && !DjangoFacet.isPresent(module)) {
|
||||
DjangoTestCase.addDjangoFacet(module);
|
||||
TemplatesService.getInstance(module).setTemplateLanguage(TemplatesService.DJANGO);
|
||||
}
|
||||
TemplatesService.getInstance(module).setTemplateLanguage(TemplatesService.DJANGO);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
TemplatesService.getInstance(myFixture.getModule()).setTemplateLanguage(TemplatesService.NONE);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
if (myConsoleView != null) {
|
||||
Disposer.dispose(myConsoleView);
|
||||
myConsoleView = null;
|
||||
}
|
||||
if (myDescriptor != null) {
|
||||
Disposer.dispose(myDescriptor);
|
||||
myDescriptor = null;
|
||||
}
|
||||
if (myRunContentExecutor != null) {
|
||||
Disposer.dispose(myRunContentExecutor);
|
||||
}
|
||||
DjangoManageTestTask.super.tearDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public abstract ConfigurationFactory getFactory();
|
||||
|
||||
@Override
|
||||
public void runTestOn(final String sdkHome) throws Exception {
|
||||
mySdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
|
||||
before();
|
||||
|
||||
final Semaphore s = new Semaphore();
|
||||
s.down();
|
||||
|
||||
|
||||
myOutput = new StringBuilder();
|
||||
myStdErr = new StringBuilder();
|
||||
myStdOut = new StringBuilder();
|
||||
|
||||
runProcess(sdkHome, s);
|
||||
|
||||
try {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
testing();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertTrue(s.waitFor(60000));
|
||||
XDebuggerTestUtil.waitForSwing();
|
||||
after();
|
||||
}
|
||||
finally {
|
||||
|
||||
disposeProcess(myProcessHandler);
|
||||
}
|
||||
}
|
||||
|
||||
private void runProcess(final String sdkHome, final Semaphore s) throws ExecutionException, IOException, InvalidSdkException {
|
||||
final ConfigurationFactory factory = getFactory();
|
||||
|
||||
if (factory == null) { // PythonTask (there is no run configuration)
|
||||
final Module module = myFixture.getModule();
|
||||
final DjangoManageTask task = new DjangoManageTask(module, DjangoBundle.message("manage.run.tab.name"), mySdk);
|
||||
|
||||
task.setWorkingDirectory(getWorkingFolder());
|
||||
task.setRunnerScript(PythonHelpersLocator.getHelperPath("pycharm/django_manage.py"));
|
||||
ImmutableList.Builder<String> parametersString =
|
||||
new ImmutableList.Builder<String>().add(getSubcommand()).add(getTestDataPath());
|
||||
|
||||
task.setParameters(parametersString.build());
|
||||
|
||||
myProcessHandler = task.createProcess(null);
|
||||
|
||||
myProcessHandler.addProcessListener(createProcessListener());
|
||||
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
final Project project = myFixture.getProject();
|
||||
myRunContentExecutor = new RunContentExecutor(project, myProcessHandler);
|
||||
myRunContentExecutor
|
||||
.withFilter(new PythonTracebackFilter(project))
|
||||
.run();
|
||||
}
|
||||
});
|
||||
s.up();
|
||||
}
|
||||
else { //run dango server and django test
|
||||
final Project project = getProject();
|
||||
final RunnerAndConfigurationSettings settings =
|
||||
RunManager.getInstance(project).createRunConfiguration("test", factory);
|
||||
|
||||
final AbstractPythonRunConfiguration config = (AbstractPythonRunConfiguration)settings.getConfiguration();
|
||||
config.addSourceRoots(DjangoTestsConfigurationType.getInstance().getDjangoTestsFactory().equals(factory));
|
||||
config.addContentRoots(DjangoTestsConfigurationType.getInstance().getDjangoTestsFactory().equals(factory));
|
||||
config.setSdkHome(sdkHome);
|
||||
config.setWorkingDirectory(getWorkingFolder());
|
||||
|
||||
new WriteAction() {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
configure(config);
|
||||
|
||||
RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
|
||||
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
|
||||
Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
|
||||
}
|
||||
}.execute();
|
||||
|
||||
final ProgramRunner runner = ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings);
|
||||
|
||||
Assert.assertTrue(runner.canRun(DefaultRunExecutor.EXECUTOR_ID, config));
|
||||
|
||||
final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
|
||||
final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
|
||||
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
runner.execute(env, new ProgramRunner.Callback() {
|
||||
@Override
|
||||
public void processStarted(RunContentDescriptor descriptor) {
|
||||
myDescriptor = descriptor;
|
||||
myProcessHandler = myDescriptor.getProcessHandler();
|
||||
myProcessHandler.addProcessListener(createProcessListener());
|
||||
myConsoleView = myDescriptor.getExecutionConsole();
|
||||
s.up();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private ProcessAdapter createProcessListener() {
|
||||
return new ProcessAdapter() {
|
||||
@Override
|
||||
public void onTextAvailable(ProcessEvent event, Key outputType) {
|
||||
myOutput.append(event.getText());
|
||||
if (outputType == ProcessOutputTypes.STDOUT) {
|
||||
myStdOut.append(event.getText());
|
||||
}
|
||||
else if (outputType == ProcessOutputTypes.STDERR) {
|
||||
myStdErr.append(event.getText());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract String getSubcommand();
|
||||
|
||||
protected void configure(AbstractPythonRunConfiguration config) throws IOException {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String output() {
|
||||
return myOutput.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String stderr() {
|
||||
return myStdErr.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String stdout() {
|
||||
return myStdOut.toString();
|
||||
}
|
||||
|
||||
public void waitForOutput(@NotNull final String string) throws InterruptedException {
|
||||
int count = 0;
|
||||
while (!output().contains(string)) {
|
||||
if (count > 10) {
|
||||
Assert.fail("'" + string + "'" + " is not present in output.\n" + output());
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTags() {
|
||||
return ImmutableSet.of("django");
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.jetbrains.django.run.DjangoServerRunConfiguration;
|
||||
import com.jetbrains.django.run.DjangoServerRunConfigurationType;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public class DjangoPathTest extends PyEnvTestCase {
|
||||
|
||||
/**
|
||||
* This string is printed after printing sys.path in djangoPath/settings.py
|
||||
*/
|
||||
public static final String THE_END_OF_SYS_PATH = "The end of sys.path";
|
||||
|
||||
public void testRunserverPath() throws IOException {
|
||||
runPythonTest(new DjangoPathTestTask() {
|
||||
|
||||
@Override
|
||||
protected void configure(AbstractPythonRunConfiguration config) throws IOException {
|
||||
final int[] ports = DjangoTemplateDebuggerTest.findFreePorts(2);
|
||||
((DjangoServerRunConfiguration)config).setPort(ports[1]);
|
||||
((DjangoServerRunConfiguration)config).setRunNoReload(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationFactory getFactory() {
|
||||
return DjangoServerRunConfigurationType.getInstance().getConfigurationFactories()[0];
|
||||
}
|
||||
|
||||
|
||||
public void testing() throws Exception {
|
||||
waitForOutput(THE_END_OF_SYS_PATH);
|
||||
|
||||
doTest(output(), getTestDataPath());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void doTest(String output, String testDataPath) {
|
||||
final String[] splittedOutput = output.split("\\n");
|
||||
final ArrayList<String> outputList = Lists.newArrayList();
|
||||
for (String s : splittedOutput) {
|
||||
if (s.equals(THE_END_OF_SYS_PATH)) {
|
||||
break;
|
||||
}
|
||||
outputList.add(norm(s));
|
||||
}
|
||||
|
||||
testDataPath = norm(testDataPath);
|
||||
|
||||
|
||||
Assert.assertEquals(testDataPath, outputList.get(1));
|
||||
|
||||
assertEquals(outputList.indexOf(testDataPath),
|
||||
outputList.lastIndexOf(testDataPath));
|
||||
}
|
||||
|
||||
private static String norm(String testDataPath) {
|
||||
return FileUtil.toSystemIndependentName(testDataPath);
|
||||
}
|
||||
|
||||
public void testManagePath() throws IOException {
|
||||
runPythonTest(new DjangoPathTestTask() {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ConfigurationFactory getFactory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void testing() throws Exception {
|
||||
waitForOutput(THE_END_OF_SYS_PATH);
|
||||
|
||||
final String[] splittedOutput = output().split("\\n");
|
||||
final ArrayList<String> outputList = Lists.newArrayList();
|
||||
for (String s : splittedOutput) {
|
||||
if (s.equals(THE_END_OF_SYS_PATH)) {
|
||||
break;
|
||||
}
|
||||
outputList.add(s);
|
||||
}
|
||||
|
||||
assertEquals(getTestDataPath(), outputList.get(1));
|
||||
assertEquals(outputList.indexOf(getTestDataPath()),
|
||||
outputList.lastIndexOf(getTestDataPath()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.jetbrains.python.fixtures.PyProfessionalTestCase;
|
||||
|
||||
/**
|
||||
* User : catherine
|
||||
*/
|
||||
public abstract class DjangoPathTestTask extends DjangoManageTestTask {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PyProfessionalTestCase.getProfessionalTestDataPath() + "/django/path/djangoPath";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSubcommand() {
|
||||
return "validate";
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.jetbrains.django.DjangoNames;
|
||||
import com.jetbrains.django.model.DjangoAdmin;
|
||||
import com.jetbrains.django.util.DjangoUtil;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.PyExecutionFixtureTestTask;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import com.jetbrains.python.psi.impl.blockEvaluator.PyBlockEvaluator;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Tests projection creation for Django
|
||||
*
|
||||
* @author Ilya.Kazakevich
|
||||
*/
|
||||
public class DjangoProjectCreationTest extends PyEnvTestCase {
|
||||
|
||||
private static final String ROOT_FOLDER_NAME = "content_root";
|
||||
private static final String WEB_SITE_NAME = "myWebSite";
|
||||
private static final String DJANGO_TAG = "django";
|
||||
private static final MyDjangoProjectCreationTest.Canonicator CANONICATOR = new MyDjangoProjectCreationTest.Canonicator();
|
||||
|
||||
public DjangoProjectCreationTest() {
|
||||
super(DJANGO_TAG);
|
||||
}
|
||||
|
||||
|
||||
// TODO: Doc
|
||||
public void testProjectWithTemplates() throws Exception {
|
||||
runPythonTest(new MyDjangoProjectCreationTest());
|
||||
}
|
||||
|
||||
private static class MyDjangoProjectCreationTest extends PyExecutionFixtureTestTask {
|
||||
@Override
|
||||
public void runTestOn(@NotNull final String sdkHome) throws Exception {
|
||||
final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
|
||||
final String djangoPath = DjangoUtil.getDjangoPath(sdk);
|
||||
assert djangoPath != null : "No django found under " + sdkHome;
|
||||
|
||||
final VirtualFile contentRoot = myFixture.getTempDirFixture().findOrCreateDir(ROOT_FOLDER_NAME);
|
||||
final String templateDir = myFixture.getTempDirFixture().findOrCreateDir(ROOT_FOLDER_NAME + "/templates_dir").getCanonicalPath();
|
||||
assert templateDir != null : "Failed to create template dirs";
|
||||
|
||||
UsefulTestCase.edt(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
new WriteAction() {
|
||||
@Override
|
||||
protected void run(@NotNull Result result) throws Throwable {
|
||||
try {
|
||||
DjangoAdmin.createProject(
|
||||
myFixture.getProject(),
|
||||
sdk,
|
||||
contentRoot,
|
||||
WEB_SITE_NAME,
|
||||
"myMainApp",
|
||||
templateDir,
|
||||
djangoPath,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
catch (final ExecutionException ex) {
|
||||
Assert.fail(ex.toString());
|
||||
}
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
});
|
||||
|
||||
final String pathToSettingsPy;
|
||||
if (DjangoAdmin.isDjangoVersionAtLeast(sdk, "1.4")) {
|
||||
pathToSettingsPy = ROOT_FOLDER_NAME + '/' + WEB_SITE_NAME + '/' + DjangoNames.SETTINGS_FILE;
|
||||
}
|
||||
else {
|
||||
pathToSettingsPy = ROOT_FOLDER_NAME + '/' + DjangoNames.SETTINGS_FILE;
|
||||
}
|
||||
|
||||
final PyFile settingsPy =
|
||||
PyUtil.as(myFixture.configureByFile(pathToSettingsPy), PyFile.class);
|
||||
Assert.assertNotNull(DjangoNames.SETTINGS_FILE + " not created", settingsPy);
|
||||
Assert.assertEquals("Bad file name for settings", DjangoNames.SETTINGS_FILE, settingsPy.getName());
|
||||
|
||||
|
||||
final PyBlockEvaluator evaluator = new PyBlockEvaluator();
|
||||
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
evaluator.evaluate(settingsPy);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
final List<String> templateDirsFromConfig = evaluator.getValueAsStringList(DjangoNames.TEMPLATE_DIRS_SETTING);
|
||||
Assert.assertThat(String.format("Failed to find %s in %s", DjangoNames.TEMPLATE_DIRS_SETTING, settingsPy), templateDirsFromConfig,
|
||||
Matchers.allOf(Matchers.notNullValue(), Matchers.not(Matchers.empty())));
|
||||
|
||||
// Canoncial path is used to prevent ".."
|
||||
Assert.assertThat("Wrong template dirs in config", Collections2.transform(templateDirsFromConfig, CANONICATOR),
|
||||
Matchers.contains(CANONICATOR.apply(templateDir)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTags() {
|
||||
return Sets.newHashSet(DJANGO_TAG);
|
||||
}
|
||||
|
||||
// Makes canoncial path from any path
|
||||
private static class Canonicator implements Function<String, String> {
|
||||
|
||||
@Override
|
||||
public String apply(final String input) {
|
||||
try {
|
||||
return new File(input).getCanonicalPath();
|
||||
}
|
||||
catch (final IOException e) {
|
||||
throw new AssertionError("Errror with file " + input + " : " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.jetbrains.django.fixtures.DjangoTestCase;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class DjangoTemplateBreakpointsTest extends DjangoTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/django/debug/";
|
||||
}
|
||||
|
||||
public void testCanSetBreakpoints() {
|
||||
prepareProject("djangoDebug");
|
||||
inFile("djangoDebug/templates/test1.html")
|
||||
.notCan(0)
|
||||
.notCan(1)
|
||||
.notCan(2)
|
||||
.can(3)
|
||||
.notCan(4)
|
||||
.can(5)
|
||||
.can(6)
|
||||
.notCan(7)
|
||||
.can(8)
|
||||
.can(9)
|
||||
.notCan(10)
|
||||
.notCan(11)
|
||||
.notCan(12);
|
||||
}
|
||||
|
||||
private OpenedTemplate inFile(String fileName) {
|
||||
return new OpenedTemplate(fileName, myFixture);
|
||||
}
|
||||
|
||||
private static class OpenedTemplate {
|
||||
private String myFile;
|
||||
private CodeInsightTestFixture myFixture;
|
||||
|
||||
private OpenedTemplate(String file, CodeInsightTestFixture fixture) {
|
||||
myFile = file;
|
||||
myFixture = fixture;
|
||||
}
|
||||
|
||||
private OpenedTemplate can(int line) {
|
||||
Assert.assertTrue("at line " + line, XDebuggerUtil.getInstance().canPutBreakpointAt(myFixture.getProject(), findFile(), line));
|
||||
return this;
|
||||
}
|
||||
|
||||
private VirtualFile findFile() {
|
||||
return myFixture.findFileInTempDir(myFile);
|
||||
}
|
||||
|
||||
private OpenedTemplate notCan(int line) {
|
||||
Assert.assertFalse("at line " + line, XDebuggerUtil.getInstance().canPutBreakpointAt(myFixture.getProject(), findFile(), line));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,361 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.xdebugger.XDebuggerTestUtil;
|
||||
import com.jetbrains.django.util.VirtualFileUtil;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.python.debugger.django.DjangoExceptionBreakpointProperties;
|
||||
import com.jetbrains.python.debugger.django.DjangoExceptionBreakpointType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class DjangoTemplateDebuggerTest extends PyEnvTestCase {
|
||||
|
||||
public void testBreakpointStopAndEval() throws IOException {
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new BreakpointStopAndEvalTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]));
|
||||
}
|
||||
|
||||
private static class BreakpointStopAndEvalTask extends DjangoEnvTestTask {
|
||||
public BreakpointStopAndEvalTask(String workingFolder, String scriptName, String scriptParameters, int port) {
|
||||
super(workingFolder, scriptName, scriptParameters, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
//setShouldPrintOutput(true);
|
||||
String file = getFilePath("/templates/test1.html");
|
||||
checkModuleForFile(getProject(), VirtualFileUtil.findFile(file));
|
||||
|
||||
toggleBreakpoint(file, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
DjangoEnvTestTask.LoadingPage page = loadPage(myPort + "/test1");
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("1");
|
||||
|
||||
resume();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("2");
|
||||
|
||||
resume();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("3");
|
||||
|
||||
resume();
|
||||
|
||||
page.get().contains("TemplateDebugging");
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: uncomment after fixing http://youtrack.jetbrains.com/issue/PY-13465
|
||||
public void testSetVal() throws IOException {
|
||||
//setShouldPrintOutput(true);
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new DjangoEnvTestTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
String file = getFilePath("/templates/test1.html");
|
||||
checkModuleForFile(getProject(), VirtualFileUtil.findFile(file));
|
||||
|
||||
toggleBreakpoint(file, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
LoadingPage page = loadPage(myPort + "/test1");
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("1");
|
||||
eval("name").hasValue("'TemplateDebugging'");
|
||||
|
||||
setVal("name", "'TemplateDjangoDebugging'");
|
||||
|
||||
resume();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("2");
|
||||
eval("name").hasValue("'TemplateDjangoDebugging'");
|
||||
|
||||
resume();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("3");
|
||||
eval("name").hasValue("'TemplateDjangoDebugging'");
|
||||
|
||||
resume();
|
||||
|
||||
page.get().contains("templatedjangodebugging");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
public void testVariableDoesNotExistExceptionBreak() throws IOException {
|
||||
//setShouldPrintOutput(true);
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new DjangoEnvTestTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
addDjangoExceptionBreakpoint(myFixture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
LoadingPage page = loadPage(myPort + "/test2");
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("1");
|
||||
|
||||
resume();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("2");
|
||||
|
||||
resume();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("3");
|
||||
|
||||
resume();
|
||||
|
||||
page.get().contains("templatedebugging");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testTemplateDoseNotExistsExceptionBreak() throws IOException {
|
||||
//setShouldPrintOutput(true);
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new DjangoEnvTestTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
addDjangoExceptionBreakpoint(myFixture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
LoadingPage page = loadPage(myPort + "/test3");
|
||||
|
||||
waitForPause();
|
||||
|
||||
resume();
|
||||
|
||||
page.get().contains("Server returned HTTP response code: 500");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testConditionalBreakpointStop() throws IOException {
|
||||
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new DjangoEnvTestTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
//setShouldPrintOutput(true);
|
||||
String file = getFilePath("/templates/test1.html");
|
||||
checkModuleForFile(getProject(), VirtualFileUtil.findFile(file));
|
||||
|
||||
toggleBreakpoint(file, 6);
|
||||
XDebuggerTestUtil.setBreakpointCondition(getProject(), 6, "x == 1 or x == 3");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
LoadingPage page = loadPage(myPort + "/test1");
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("1");
|
||||
|
||||
resume();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("3");
|
||||
|
||||
resume();
|
||||
|
||||
page.get().contains("TemplateDebugging");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testBreakpointStopAndStepOver() throws IOException {
|
||||
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new DjangoEnvTestTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
//setShouldPrintOutput(true);
|
||||
String file = getFilePath("/templates/test4.html");
|
||||
checkModuleForFile(getProject(), VirtualFileUtil.findFile(file));
|
||||
|
||||
toggleBreakpoint(file, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
loadPage(ports[1] + "/test4");
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("x").hasValue("1");
|
||||
|
||||
stepOver();
|
||||
|
||||
waitForPause();
|
||||
|
||||
stepOver();
|
||||
|
||||
waitForPause();
|
||||
|
||||
eval("y").hasValue("1");
|
||||
|
||||
resume();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testBreakpointLogExpression() throws IOException {
|
||||
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new DjangoEnvTestTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
//setShouldPrintOutput(true);
|
||||
String file = getFilePath("/templates/test1.html");
|
||||
checkModuleForFile(getProject(), VirtualFileUtil.findFile(file));
|
||||
|
||||
toggleBreakpoint(file, 6);
|
||||
XDebuggerTestUtil.setBreakpointLogExpression(getProject(), 6, "'x = %d'%x");
|
||||
|
||||
useLongTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
loadPage(ports[1] + "/test1");
|
||||
|
||||
waitForPause();
|
||||
resume();
|
||||
waitForOutput("x = 2");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void testStepInto() throws IOException {
|
||||
|
||||
final int[] ports = findFreePorts(2);
|
||||
runPythonTest(new DjangoEnvTestTask("/djangoDebug", "manage.py", "runserver --noreload ", ports[1]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
//setShouldPrintOutput(true);
|
||||
String file = getFilePath("/templates/test5.html");
|
||||
checkModuleForFile(getProject(), VirtualFileUtil.findFile(file));
|
||||
|
||||
toggleBreakpoint(file, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testing() throws Exception {
|
||||
waitForStart();
|
||||
|
||||
loadPage(ports[1] + "/test5");
|
||||
|
||||
waitForPause();
|
||||
stepInto();
|
||||
waitForPause();
|
||||
stepOver();
|
||||
waitForPause();
|
||||
|
||||
eval("res").hasValue("'Result'");
|
||||
stepOver();
|
||||
waitForPause();
|
||||
eval("name").hasValue("'TemplateDebugging5'");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void addDjangoExceptionBreakpoint(IdeaProjectTestFixture fixture) {
|
||||
XDebuggerTestUtil.addBreakpoint(fixture.getProject(), DjangoExceptionBreakpointType.class, new DjangoExceptionBreakpointProperties());
|
||||
}
|
||||
|
||||
public static int[] findFreePorts(int count)
|
||||
throws IOException {
|
||||
ServerSocket[] servers = new ServerSocket[count];
|
||||
int[] port = new int[count];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
servers[i] = new ServerSocket(0);
|
||||
port[i] = servers[i].getLocalPort();
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
servers[i].close();
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
|
||||
public void testBreakpointStopAndEvalInAutoReloadMode() throws IOException {
|
||||
final int[] ports = findFreePorts(4);
|
||||
BreakpointStopAndEvalTask testTask = new BreakpointStopAndEvalTask("/djangoDebug", "manage.py", "runserver ", ports[3]) {
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
super.before();
|
||||
useLongTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTags() {
|
||||
Set<String> tags = Sets.newHashSet(super.getTags());
|
||||
tags.add("-django13"); //Django 1.3 doesn't work in reload mode on Unix
|
||||
return tags;
|
||||
}
|
||||
};
|
||||
//testTask.setShouldPrintOutput(true);
|
||||
testTask.setMultiprocessDebug(true);
|
||||
runPythonTest(testTask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.django.facet.DjangoFacet;
|
||||
import com.jetbrains.django.facet.DjangoFacetConfiguration;
|
||||
import com.jetbrains.django.testRunner.DjangoTestsConfigurationType;
|
||||
import com.jetbrains.django.testRunner.DjangoTestsRunConfiguration;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.python.packaging.PyExternalProcessException;
|
||||
import com.jetbrains.python.packaging.PyPackage;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
import com.jetbrains.python.packaging.PyRequirement;
|
||||
import com.jetbrains.python.run.AbstractPythonRunConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User : ktisha
|
||||
*/
|
||||
public class DjangoTestRunnerTest extends PyEnvTestCase {
|
||||
|
||||
private static void doTest(@NotNull final String output, @NotNull final String testDataPath) {
|
||||
final String[] splittedOutput = output.split("\\n");
|
||||
final ArrayList<String> outputList = Lists.newArrayList();
|
||||
boolean add = false;
|
||||
for (String s : splittedOutput) {
|
||||
if ("sys.path end".equals(s)) add = false;
|
||||
if (add) outputList.add(norm(s));
|
||||
if ("sys.path start".equals(s)) add = true;
|
||||
}
|
||||
assertEquals(outputList.indexOf(testDataPath),
|
||||
outputList.lastIndexOf(testDataPath));
|
||||
}
|
||||
|
||||
private static String norm(String testDataPath) {
|
||||
return FileUtil.toSystemIndependentName(testDataPath);
|
||||
}
|
||||
|
||||
private void doTest(@Nullable final String projectRoot, @Nullable final String settings,
|
||||
@Nullable final String markAsSource, @Nullable final String customSettings) {
|
||||
final String name = getTestName(false);
|
||||
runPythonTest(new DjangoTestRunnerTestTask() {
|
||||
@Override
|
||||
public ConfigurationFactory getFactory() {
|
||||
return DjangoTestsConfigurationType.getInstance().getConfigurationFactories()[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(AbstractPythonRunConfiguration config) {
|
||||
String target = "myapp.SimpleTest";
|
||||
try {
|
||||
final PyPackage django = PyPackageManager.getInstance(config.getSdk()).findInstalledPackage("django");
|
||||
if (django != null) {
|
||||
if (django.matches(PyRequirement.fromStringGuaranteed("django>=1.6a"))) {
|
||||
target = "myapp.tests.SimpleTest";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (PyExternalProcessException ignored) {
|
||||
}
|
||||
|
||||
((DjangoTestsRunConfiguration)config).setTarget(target);
|
||||
if (customSettings != null)
|
||||
((DjangoTestsRunConfiguration)config).setSettingsFile(getTestDataPath() + customSettings);
|
||||
((DjangoTestsRunConfiguration)config).useCustomSettings(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getContentRoots() {
|
||||
return markAsSource == null ? Lists.<String>newArrayList() : Lists.newArrayList(markAsSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void before() throws Exception {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
final Module module = myFixture.getModule();
|
||||
final DjangoFacet djangoFacet = DjangoFacet.getInstance(module);
|
||||
if (djangoFacet != null && projectRoot != null && settings != null) {
|
||||
final DjangoFacetConfiguration configuration = djangoFacet.getConfiguration();
|
||||
configuration.setProjectRootPath(getTestDataPath() + projectRoot);
|
||||
configuration.setSettingsFilePath(settings);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testing() throws Exception {
|
||||
waitForOutput("Process finished with exit code 0");
|
||||
doTest(output(), norm(getTestDataPath()));
|
||||
}
|
||||
|
||||
@Override
|
||||
String getTestName() {
|
||||
return name;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testDjango11() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDjango12() {
|
||||
doTest("", "settings.py", "", null);
|
||||
}
|
||||
|
||||
public void testDjango13() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(null, null, null, null);
|
||||
}
|
||||
|
||||
public void testDjango14() {
|
||||
doTest("", "Django14/settings.py", null, null);
|
||||
}
|
||||
|
||||
public void testDjango15() {
|
||||
doTest("", "Django15/settings.py", null, null);
|
||||
}
|
||||
|
||||
public void testRoot13() {
|
||||
doTest("/Django13", "settings.py", null, null);
|
||||
}
|
||||
|
||||
public void testRoot() {
|
||||
doTest("/DjangoRoot", "DjangoRoot/settings.py", null, null);
|
||||
}
|
||||
|
||||
public void testRootMarked() {
|
||||
doTest("/DjangoRoot", "DjangoRoot/settings.py", "/DjangoRoot", null);
|
||||
}
|
||||
|
||||
public void testSameNamedDir() {
|
||||
doTest("/web/SameNamedDir", "settings.py", null, null);
|
||||
}
|
||||
|
||||
public void testCustomSettings() {
|
||||
doTest(null, null, null, "/custom_settings.py");
|
||||
}
|
||||
|
||||
public void testInstalledApps() {
|
||||
doTest("/InstalledApps", "/config/settings/installedapps.py", null, "/config/settings/installedapps.py");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.jetbrains.env.django;
|
||||
|
||||
import com.jetbrains.python.fixtures.PyProfessionalTestCase;
|
||||
|
||||
/**
|
||||
* User : ktisha
|
||||
*/
|
||||
public abstract class DjangoTestRunnerTestTask extends DjangoManageTestTask {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PyProfessionalTestCase.getProfessionalTestDataPath() + "/django/testRunner/" + getTestName();
|
||||
}
|
||||
|
||||
abstract String getTestName();
|
||||
|
||||
@Override
|
||||
protected String getSubcommand() {
|
||||
return "validate";
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.xdebugger.*;
|
||||
import com.intellij.xdebugger.frame.XValue;
|
||||
import com.jetbrains.django.util.VirtualFileUtil;
|
||||
import com.jetbrains.env.PyExecutionFixtureTestTask;
|
||||
import com.jetbrains.python.console.PythonDebugLanguageConsoleView;
|
||||
import com.jetbrains.python.debugger.PyDebugProcess;
|
||||
@@ -162,7 +162,7 @@ public abstract class PyBaseDebuggerTask extends PyExecutionFixtureTestTask {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VirtualFile f = VirtualFileUtil.findFile(file);
|
||||
VirtualFile f = LocalFileSystem.getInstance().findFileByPath(file);
|
||||
Assert.assertNotNull(f);
|
||||
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(f);
|
||||
Assert.assertNotNull(jarRoot);
|
||||
@@ -176,14 +176,14 @@ public abstract class PyBaseDebuggerTask extends PyExecutionFixtureTestTask {
|
||||
}
|
||||
|
||||
public boolean canPutBreakpointAt(Project project, String file, int line) {
|
||||
VirtualFile vFile = VirtualFileUtil.findFile(file);
|
||||
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(file);
|
||||
Assert.assertNotNull(vFile);
|
||||
return XDebuggerUtil.getInstance().canPutBreakpointAt(project, vFile, line);
|
||||
}
|
||||
|
||||
private void doToggleBreakpoint(String file, int line) {
|
||||
Assert.assertTrue(canPutBreakpointAt(getProject(), file, line));
|
||||
XDebuggerTestUtil.toggleBreakpoint(getProject(), VirtualFileUtil.findFile(file), line);
|
||||
XDebuggerTestUtil.toggleBreakpoint(getProject(), LocalFileSystem.getInstance().findFileByPath(file), line);
|
||||
}
|
||||
|
||||
protected Variable eval(String name) throws InterruptedException {
|
||||
|
||||
@@ -1,226 +0,0 @@
|
||||
package com.jetbrains.env.remote;
|
||||
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
||||
import com.intellij.execution.executors.DefaultDebugExecutor;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.process.ProcessOutput;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.xdebugger.*;
|
||||
import com.jetbrains.env.python.debug.PyBaseDebuggerTask;
|
||||
import com.jetbrains.python.PythonHelpersLocator;
|
||||
import com.jetbrains.python.debugger.remote.*;
|
||||
import com.jetbrains.python.debugger.remote.vfs.PyRemotePositionConverter;
|
||||
import com.jetbrains.python.sdk.PySdkUtil;
|
||||
import com.jetbrains.python.sdk.PythonEnvUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class PyRemoteDebuggerTask extends PyBaseDebuggerTask {
|
||||
private Semaphore mySessionInitializedSemaphore;
|
||||
|
||||
public PyRemoteDebuggerTask() {
|
||||
}
|
||||
|
||||
public PyRemoteDebuggerTask(String workingFolder, String scriptName, String scriptParameters) {
|
||||
setWorkingFolder(getTestDataPath() + workingFolder);
|
||||
setScriptName(scriptName);
|
||||
setScriptParameters(scriptParameters);
|
||||
}
|
||||
|
||||
public PyRemoteDebuggerTask(String workingFolder, String scriptName) {
|
||||
this(workingFolder, scriptName, null);
|
||||
}
|
||||
|
||||
public void runTestOn(final String sdkHome) throws Exception {
|
||||
final Project project = getProject();
|
||||
|
||||
final ConfigurationFactory factory = PyRemoteDebugConfigurationType.getInstance().getConfigurationFactories()[0];
|
||||
|
||||
|
||||
final RunnerAndConfigurationSettings settings =
|
||||
RunManager.getInstance(project).createRunConfiguration("test", factory);
|
||||
|
||||
|
||||
PyRemoteDebugConfiguration config = (PyRemoteDebugConfiguration)settings.getConfiguration();
|
||||
|
||||
|
||||
new WriteAction() {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
|
||||
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
|
||||
Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
|
||||
}
|
||||
}.execute();
|
||||
|
||||
final PyRemoteDebugRunner runner = (PyRemoteDebugRunner)ProgramRunnerUtil.getRunner(DefaultDebugExecutor.EXECUTOR_ID, settings);
|
||||
Assert.assertTrue(runner.canRun(DefaultDebugExecutor.EXECUTOR_ID, config));
|
||||
|
||||
final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
|
||||
final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
|
||||
|
||||
|
||||
final PyRemoteDebugCommandLineState pyState = (PyRemoteDebugCommandLineState)config.getState(executor, env);
|
||||
assert pyState != null;
|
||||
|
||||
final ServerSocket serverSocket;
|
||||
final PyRemoteDebugConfiguration conf = (PyRemoteDebugConfiguration)env.getRunProfile();
|
||||
try {
|
||||
//noinspection SocketOpenedButNotSafelyClosed
|
||||
serverSocket = new ServerSocket(conf.getPort());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ExecutionException("Failed to find free socket port", e);
|
||||
}
|
||||
|
||||
setProcessCanTerminate(false);
|
||||
|
||||
mySessionInitializedSemaphore = new Semaphore(0);
|
||||
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final ExecutionResult res =
|
||||
pyState.execute(executor, runner);
|
||||
|
||||
|
||||
mySession = XDebuggerManager.getInstance(project).
|
||||
startSession(runner, env, env.getContentToReuse(), new XDebugProcessStarter() {
|
||||
@NotNull
|
||||
public XDebugProcess start(@NotNull final XDebugSession session) {
|
||||
myDebugProcess =
|
||||
new PyRemoteDebugProcess(session, serverSocket, res.getExecutionConsole(),
|
||||
res.getProcessHandler(), null);
|
||||
myDebugProcess.setPositionConverter(new PyRemotePositionConverter(myDebugProcess, conf.getMappingSettings()));
|
||||
|
||||
myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {
|
||||
|
||||
@Override
|
||||
public void onTextAvailable(ProcessEvent event, Key outputType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processTerminated(ProcessEvent event) {
|
||||
myTerminateSemaphore.release();
|
||||
if (event.getExitCode() != 0 && !myProcessCanTerminate) {
|
||||
Assert.fail("Process terminated unexpectedly\n" + output());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
myPausedSemaphore = new Semaphore(0);
|
||||
|
||||
myTerminateSemaphore = new Semaphore(0);
|
||||
|
||||
return myDebugProcess;
|
||||
}
|
||||
});
|
||||
|
||||
mySession.addSessionListener(new XDebugSessionAdapter() {
|
||||
@Override
|
||||
public void sessionPaused() {
|
||||
if (myPausedSemaphore != null) {
|
||||
myPausedSemaphore.release();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mySessionInitializedSemaphore.release();
|
||||
}
|
||||
catch (ExecutionException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
before();
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (myDebugProcess == null || !myDebugProcess.isWaitingForConnection()) {
|
||||
try {
|
||||
Thread.sleep(300);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
ProcessOutput output =
|
||||
PySdkUtil
|
||||
.getProcessOutput(getWorkingFolder(), new String[]{sdkHome, getScriptPath(), Integer.toString(serverSocket.getLocalPort())},
|
||||
new String[]{
|
||||
PythonEnvUtil.PYTHONUNBUFFERED + "=x",
|
||||
PythonEnvUtil.PYTHONPATH + "=" + PythonHelpersLocator.getHelpersRoot()}, 0);
|
||||
checkOutput(output);
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
OutputPrinter myOutputPrinter = null;
|
||||
if (shouldPrintOutput)
|
||||
|
||||
{
|
||||
myOutputPrinter = new OutputPrinter();
|
||||
myOutputPrinter.start();
|
||||
}
|
||||
|
||||
|
||||
waitFor(mySessionInitializedSemaphore);
|
||||
|
||||
doTest(myOutputPrinter);
|
||||
}
|
||||
|
||||
protected void checkOutput(ProcessOutput output) {
|
||||
}
|
||||
|
||||
protected void stopDebugServer() throws InterruptedException {
|
||||
if (myDebugProcess != null) {
|
||||
ProcessHandler h = myDebugProcess.getProcessHandler();
|
||||
h.destroyProcess();
|
||||
h.detachProcess();
|
||||
|
||||
if (!h.isStartNotified()) {
|
||||
h.startNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void disposeDebugProcess() throws InterruptedException {
|
||||
if (myDebugProcess != null) {
|
||||
|
||||
myDebugProcess.stop();
|
||||
|
||||
ProcessHandler h = myDebugProcess.getProcessHandler();
|
||||
if (!h.isProcessTerminated()) {
|
||||
|
||||
h.destroyProcess();
|
||||
|
||||
if (!waitFor(h)) {
|
||||
new Throwable("Cannot stop debugger process").printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.jetbrains.env.remote;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.env.PyEnvTaskRunner;
|
||||
import com.jetbrains.env.PyExecutionFixtureTestTask;
|
||||
import com.jetbrains.env.PyTestTask;
|
||||
import com.jetbrains.env.python.PythonDebuggerTest;
|
||||
import com.jetbrains.python.remote.PyRemoteSdkAdditionalData;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class PyRemoteDebuggerTest extends PythonDebuggerTest {
|
||||
@Override
|
||||
protected void doRunTests(PyTestTask testTask, String testName, List<String> roots) {
|
||||
if (RUN_REMOTE && PyTestRemoteSdkProvider.shouldRunRemoteSdk(testTask)) {
|
||||
if (PyTestRemoteSdkProvider.canRunRemoteSdk()) {
|
||||
PyEnvTaskRunner remoteRunner = new RemoteTaskRunner(roots);
|
||||
remoteRunner.runTask(testTask, testName);
|
||||
}
|
||||
else {
|
||||
if (PyTestRemoteSdkProvider.shouldFailWhenCantRunRemote()) {
|
||||
fail("Cant run with remote sdk: password isn't set");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoteTaskRunner extends PyEnvTaskRunner {
|
||||
private RemoteTaskRunner(List<String> roots) {
|
||||
super(roots);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getExecutable(String root, PyTestTask testTask) {
|
||||
try {
|
||||
final Sdk sdk = PyTestRemoteSdkProvider.getInstance().getSdk(getProject(testTask), super.getExecutable(root, testTask));
|
||||
|
||||
if (ProjectJdkTable.getInstance().findJdk(sdk.getName()) == null) {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProjectJdkTable.getInstance().addJdk(sdk);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return ((PyRemoteSdkAdditionalData)sdk.getSdkAdditionalData()).getRemoteSdkCredentials(false).getSdkId();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Project getProject(PyTestTask task) {
|
||||
if (task instanceof PyExecutionFixtureTestTask) {
|
||||
return ((PyExecutionFixtureTestTask)task).getProject();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldRun(String root, PyTestTask task) {
|
||||
return !isJython(super.getExecutable(root, task)); //TODO: make remote tests work for jython
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getEnvType() {
|
||||
return "remote";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package com.jetbrains.env.remote;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.remote.RemoteCredentialsHolder;
|
||||
import com.intellij.remote.RemoteSdkException;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.jetbrains.env.PyTestTask;
|
||||
import com.jetbrains.python.remote.PyRemoteInterpreterManagerImpl;
|
||||
import com.jetbrains.python.remote.PyRemoteSdkAdditionalData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class PyTestRemoteSdkProvider {
|
||||
public static final String SSH_PASSWORD = "SSH_PASSWORD";
|
||||
public static final String LOCAL_SSH_WITHOUT_PASSWORD = "LOCAL_SSH_WITHOUT_PASSWORD";
|
||||
private final PyRemoteInterpreterManagerImpl myInterpreterManager;
|
||||
private static final String SSH_USER_NAME = "SSH_USER_NAME";
|
||||
|
||||
private Project myProject;
|
||||
|
||||
private static PyTestRemoteSdkProvider INSTANCE = null;
|
||||
|
||||
public synchronized static PyTestRemoteSdkProvider getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new PyTestRemoteSdkProvider();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public PyTestRemoteSdkProvider() {
|
||||
myInterpreterManager = new PyRemoteInterpreterManagerImpl();
|
||||
}
|
||||
|
||||
private final LoadingCache<String, Sdk> mySdkTable = CacheBuilder.newBuilder()
|
||||
.build(
|
||||
new CacheLoader<String, Sdk>() {
|
||||
@Override
|
||||
public Sdk load(String key) throws Exception {
|
||||
return createSdk(key);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public Sdk getSdk(Project project, String sdkPath) throws ExecutionException {
|
||||
myProject = project;
|
||||
return mySdkTable.get(sdkPath);
|
||||
}
|
||||
|
||||
private Sdk createSdk(String interpreterPath) throws RemoteSdkException {
|
||||
try {
|
||||
PyRemoteSdkAdditionalData data = createRemoteSdkData(interpreterPath);
|
||||
|
||||
final Sdk sdk = myInterpreterManager.createRemoteSdk(myProject, data, null, Lists.<Sdk>newArrayList());
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myInterpreterManager.initSdk(sdk, myProject, null);
|
||||
}
|
||||
});
|
||||
|
||||
return sdk;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static RemoteCredentialsHolder getTestSdkCredentials() {
|
||||
RemoteCredentialsHolder data = new RemoteCredentialsHolder();
|
||||
data.setHost("localhost");
|
||||
data.setPort(22);
|
||||
data.setUserName(getUserName());
|
||||
data.setPassword(getPassword());
|
||||
return data;
|
||||
}
|
||||
|
||||
private static PyRemoteSdkAdditionalData createRemoteSdkData(final String path) throws IOException {
|
||||
PyRemoteSdkAdditionalData data = new PyRemoteSdkAdditionalData(path);
|
||||
data.setSshCredentials(getTestSdkCredentials());
|
||||
data.setInterpreterPath(path);
|
||||
try {
|
||||
data.setHelpersPath(getTempHelpersPath(path));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static boolean canRunRemoteSdk() {
|
||||
return isPasswordSpecified();
|
||||
}
|
||||
|
||||
private static boolean isPasswordSpecified() {
|
||||
return !StringUtil.isEmpty(System.getenv(LOCAL_SSH_WITHOUT_PASSWORD)) || !StringUtil.isEmpty(getPassword());
|
||||
}
|
||||
|
||||
public static boolean shouldFailWhenCantRunRemote() {
|
||||
return !StringUtil.isEmpty(System.getenv("FAIL_WHEN_CANT_RUN_REMOTE")) || UsefulTestCase.IS_UNDER_TEAMCITY;
|
||||
}
|
||||
|
||||
private static String getTempHelpersPath(@NotNull String interpreterPath) throws IOException {
|
||||
final File dir = new File("/tmp");
|
||||
|
||||
File tmpDir = FileUtil.createTempDirectory(dir, "pycharm_helpers_", "_" + Math.abs(
|
||||
Hashing.md5().hashUnencodedChars(interpreterPath).asInt()), true);
|
||||
return tmpDir.getPath();
|
||||
}
|
||||
|
||||
public static String getUserName() {
|
||||
String userName = System.getenv(SSH_USER_NAME);
|
||||
return StringUtil.isEmpty(userName) ? System.getProperty("user.name") : userName;
|
||||
}
|
||||
|
||||
public static String getPassword() {
|
||||
return System.getenv(SSH_PASSWORD);
|
||||
}
|
||||
|
||||
public static boolean shouldRunRemoteSdk(PyTestTask task) {
|
||||
return SystemInfo.isUnix;
|
||||
}
|
||||
}
|
||||
142
python/testSrc/com/jetbrains/python/sdkTools/PyTestSdkTools.java
Normal file
142
python/testSrc/com/jetbrains/python/sdkTools/PyTestSdkTools.java
Normal file
@@ -0,0 +1,142 @@
|
||||
package com.jetbrains.python.sdkTools;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkModificator;
|
||||
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.jetbrains.python.sdk.InvalidSdkException;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import com.jetbrains.python.sdk.skeletons.PySkeletonRefresher;
|
||||
import com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Engine to create SDK for tests.
|
||||
* See {@link #createTempSdk(com.intellij.openapi.vfs.VirtualFile, SdkCreationType, com.intellij.openapi.module.Module)}
|
||||
*
|
||||
* @author Ilya.Kazakevich
|
||||
*/
|
||||
public final class PyTestSdkTools {
|
||||
|
||||
private static final Sdk[] NO_SDK = new Sdk[0];
|
||||
|
||||
private PyTestSdkTools() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates SDK by its path and associates it with module.
|
||||
*
|
||||
* @param sdkHome path to sdk
|
||||
* @param sdkCreationType SDK creation strategy (see {@link SdkCreationType} doc)
|
||||
* @return sdk
|
||||
*/
|
||||
@NotNull
|
||||
public static Sdk createTempSdk(@NotNull final VirtualFile sdkHome,
|
||||
@NotNull final SdkCreationType sdkCreationType,
|
||||
@NotNull final Module module
|
||||
)
|
||||
throws InvalidSdkException, IOException {
|
||||
final Ref<Sdk> ref = Ref.create();
|
||||
UsefulTestCase.edt(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Sdk sdk = SdkConfigurationUtil.setupSdk(NO_SDK, sdkHome, PythonSdkType.getInstance(), true, null, null);
|
||||
Assert.assertNotNull("Failed to create SDK on " + sdkHome, sdk);
|
||||
ref.set(sdk);
|
||||
}
|
||||
});
|
||||
final Sdk sdk = ref.get();
|
||||
if (sdkCreationType != SdkCreationType.EMPTY_SDK) {
|
||||
generateTempSkeletonsOrPackages(sdk, sdkCreationType == SdkCreationType.SDK_PACKAGES_AND_SKELETONS, module);
|
||||
}
|
||||
UsefulTestCase.edt(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SdkConfigurationUtil.addSdk(sdk);
|
||||
}
|
||||
});
|
||||
return sdk;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds installed eggs to SDK, generates skeletons (optionally) and associates it with modle.
|
||||
*
|
||||
* @param sdk sdk to process
|
||||
* @param addSkeletons add skeletons or only packages
|
||||
* @param module module to associate with
|
||||
* @throws InvalidSdkException bas sdk
|
||||
* @throws IOException failed to read eggs
|
||||
*/
|
||||
private static void generateTempSkeletonsOrPackages(@NotNull final Sdk sdk,
|
||||
final boolean addSkeletons,
|
||||
@NotNull final Module module)
|
||||
throws InvalidSdkException, IOException {
|
||||
final Project project = module.getProject();
|
||||
ModuleRootModificationUtil.setModuleSdk(module, sdk);
|
||||
|
||||
UsefulTestCase.edt(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProjectRootManager.getInstance(project).setProjectSdk(sdk);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
final SdkModificator modificator = sdk.getSdkModificator();
|
||||
modificator.removeRoots(OrderRootType.CLASSES);
|
||||
|
||||
for (final String path : PythonSdkType.getSysPathsFromScript(sdk.getHomePath())) {
|
||||
PythonSdkType.addSdkRoot(modificator, path);
|
||||
}
|
||||
if (!addSkeletons) {
|
||||
UsefulTestCase.edt(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
modificator.commitChanges();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
final File tempDir = FileUtil.createTempDirectory(PyTestSdkTools.class.getName(), null);
|
||||
final File skeletonsDir = new File(tempDir, PythonSdkType.SKELETON_DIR_NAME);
|
||||
FileUtil.createDirectory(skeletonsDir);
|
||||
final String skeletonsPath = skeletonsDir.toString();
|
||||
PythonSdkType.addSdkRoot(modificator, skeletonsPath);
|
||||
|
||||
UsefulTestCase.edt(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
modificator.commitChanges();
|
||||
}
|
||||
});
|
||||
|
||||
final SkeletonVersionChecker checker = new SkeletonVersionChecker(0);
|
||||
final PySkeletonRefresher refresher = new PySkeletonRefresher(project, null, sdk, skeletonsPath, null, null);
|
||||
final List<String> errors = refresher.regenerateSkeletons(checker, null);
|
||||
Assert.assertThat("Errors found", errors, Matchers.empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.jetbrains.python.sdkTools;
|
||||
|
||||
/**
|
||||
* SDK creation type
|
||||
* @author Ilya.Kazakevich
|
||||
*/
|
||||
public enum SdkCreationType {
|
||||
/**
|
||||
* SDK only (no packages nor skeletons)
|
||||
*/
|
||||
EMPTY_SDK,
|
||||
/**
|
||||
* SDK + installed packages from syspath
|
||||
*/
|
||||
SDK_PACKAGES_ONLY,
|
||||
/**
|
||||
* SDK + installed packages from syspath + skeletons
|
||||
*/
|
||||
SDK_PACKAGES_AND_SKELETONS
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Engine to create SDK in tests.
|
||||
* See {@link com.jetbrains.python.sdkTools.PyTestSdkTools}
|
||||
* @author Ilya.Kazakevich
|
||||
*/
|
||||
package com.jetbrains.python.sdkTools;
|
||||
@@ -16,6 +16,9 @@
|
||||
<orderEntry type="module" module-name="python-ide-community" />
|
||||
<orderEntry type="module" module-name="python-helpers" scope="RUNTIME" />
|
||||
<orderEntry type="library" name="Groovy" level="project" />
|
||||
<orderEntry type="module" module-name="xdebugger-impl" scope="TEST" />
|
||||
<orderEntry type="module" module-name="python-pydev" scope="TEST" />
|
||||
<orderEntry type="module" module-name="smRunner" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user