use of org.python.pydev.shared_core.callbacks.ICallbackListener in project Pydev by fabioz.
the class TddTestWorkbench method checkCreateNewModule3.
private void checkCreateNewModule3() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
TddCodeGenerationQuickFixParticipant quickFix;
PySelection ps;
List<ICompletionProposalHandle> props;
IFile mod2 = initFile.getParent().getParent().getParent().getFile(new Path("newpack/module_new.py"));
final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {
@Override
public Object call(PyEdit obj) {
pyEditCreated.add(obj);
return null;
}
};
PyEdit.onPyEditCreated.registerListener(listener);
try {
// Create module
// give it a bit more time...
goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
mod1Contents = "" + "import newpack.module_new";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
props = waitForQuickFixProps(quickFix, ps, offset);
assertTrue(!mod2.exists());
findCompletion(props, "Create newpack.module_new module").apply(editor.getISourceViewer(), '\n', 0, offset);
assertTrue(mod2.exists());
assertEquals(1, pyEditCreated.size());
PyEdit editCreated = pyEditCreated.get(0);
// Create class at module
mod1Contents = "" + "from newpack import module_new\n" + "module_new.NewClass";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
props = waitForQuickFixProps(quickFix, ps, offset);
findCompletion(props, "Create NewClass class at module_new.py").apply(editor.getISourceViewer(), '\n', 0, offset);
String contents = editCreated.getDocument().get();
assertContentsEqual("" + "class NewClass(object):\n" + " pass\n" + "\n" + "\n" + "", contents);
editCreated.getSite().getPage().saveEditor(editCreated, false);
// Create __init__ at class.
mod1Contents = "" + "'''\n" + "'''\n" + "" + "def bar():\n" + " from newpack import module_new\n" + // the 'undefined param' will be the error
" module_new.NewClass(param)";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
props = waitForQuickFixProps(quickFix, ps, offset);
findCompletion(props, "Create NewClass __init__ (newpack.module_new)").apply(editor.getISourceViewer(), '\n', 0, offset);
contents = editCreated.getDocument().get();
assertContentsEqual("" + "class NewClass(object):\n" + " \n" + " \n" + " def __init__(self, param):\n" + " pass\n" + " \n" + " \n" + "\n" + "\n" + "\n" + "", contents);
} finally {
for (PyEdit edit : pyEditCreated) {
edit.close(false);
}
PyEdit.onPyEditCreated.unregisterListener(listener);
mod2.delete(true, null);
}
}
use of org.python.pydev.shared_core.callbacks.ICallbackListener in project Pydev by fabioz.
the class TddTestWorkbench method checkCreateNewModuleWithClass3.
private void checkCreateNewModuleWithClass3() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
TddCodeGenerationQuickFixParticipant quickFix;
PySelection ps;
List<ICompletionProposalHandle> props;
IFile mod2 = initFile.getParent().getParent().getParent().getFile(new Path("newpack2/module_new9.py"));
final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {
@Override
public Object call(PyEdit obj) {
pyEditCreated.add(obj);
return null;
}
};
PyEdit.onPyEditCreated.registerListener(listener);
try {
// give it a bit more time...
goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
mod1Contents = "" + "class Foo:\n from newpack2.module_new9 import Foo";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
props = waitForQuickFixProps(quickFix, ps, offset);
assertTrue(!mod2.exists());
findCompletion(props, "Create Foo class at new module newpack2.module_new9").apply(editor.getISourceViewer(), '\n', 0, offset);
assertTrue("Expected: " + mod2 + " to exist.", mod2.exists());
assertEquals(1, pyEditCreated.size());
} finally {
for (PyEdit edit : pyEditCreated) {
edit.close(false);
}
PyEdit.onPyEditCreated.unregisterListener(listener);
mod2.delete(true, null);
}
}
use of org.python.pydev.shared_core.callbacks.ICallbackListener in project Pydev by fabioz.
the class TddTestWorkbench method checkCreateNewModule.
private void checkCreateNewModule() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
TddCodeGenerationQuickFixParticipant quickFix;
PySelection ps;
IFile mod2 = initFile.getParent().getFile(new Path("module_new.py"));
final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {
@Override
public Object call(PyEdit obj) {
pyEditCreated.add(obj);
return null;
}
};
PyEdit.onPyEditCreated.registerListener(listener);
try {
// give it a bit more time...
goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
mod1Contents = "" + "import pack1.pack2.module_new";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
assertTrue(!mod2.exists());
waitForQuickFixProps(quickFix, ps, offset, "Create pack1.pack2.module_new module").apply(editor.getISourceViewer(), '\n', 0, offset);
assertTrue(mod2.exists());
assertEquals(1, pyEditCreated.size());
} finally {
for (PyEdit edit : pyEditCreated) {
edit.close(false);
}
PyEdit.onPyEditCreated.unregisterListener(listener);
mod2.delete(true, null);
}
}
use of org.python.pydev.shared_core.callbacks.ICallbackListener in project Pydev by fabioz.
the class TddTestWorkbench method checkCreateNewModule4.
private void checkCreateNewModule4() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
TddCodeGenerationQuickFixParticipant quickFix;
PySelection ps;
IFile mod3 = initFile.getParent().getFile(new Path("module_new3.py"));
final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {
@Override
public Object call(PyEdit obj) {
pyEditCreated.add(obj);
return null;
}
};
PyEdit.onPyEditCreated.registerListener(listener);
try {
// give it a bit more time...
goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
mod1Contents = "" + "from pack1.pack2 import module_new3";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
assertTrue(!mod3.exists());
waitForQuickFixProps(quickFix, ps, offset, "Create module_new3 module").apply(editor.getISourceViewer(), '\n', 0, offset);
assertTrue(mod3.exists());
assertEquals(1, pyEditCreated.size());
} finally {
for (PyEdit edit : pyEditCreated) {
edit.close(false);
}
PyEdit.onPyEditCreated.unregisterListener(listener);
mod3.delete(true, null);
}
}
use of org.python.pydev.shared_core.callbacks.ICallbackListener in project Pydev by fabioz.
the class InterativeConsoleCommandsPreferencesEditorTest method testInteractiveConsoleCommandsPreferencesEditor.
public void testInteractiveConsoleCommandsPreferencesEditor() throws Exception {
InterativeConsoleCommandsPreferencesEditor editor = new InterativeConsoleCommandsPreferencesEditor();
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
Shell parent = new Shell(display);
parent.setLayout(new FillLayout());
editor.createContents(parent);
InteractiveConsoleCommand cmd = new InteractiveConsoleCommand("Plot");
cmd.keybinding = "F3";
cmd.commandText = "some text";
editor.addCommand(cmd);
assertEquals(editor.getCombo().getItemCount(), 1);
editor.performSave();
editor.loadCommands();
assertEquals(editor.getCombo().getItemCount(), 1);
assertEquals("Plot", editor.getCombo().getText());
editor.removeSelectedCommand();
assertEquals("", editor.getCombo().getText());
assertEquals(editor.getCombo().getItemCount(), 0);
cmd = new InteractiveConsoleCommand("Plot");
editor.addCommand(cmd);
assertEquals("Plot", editor.getCombo().getText());
editor.setCommandText("Plot0");
editor.setKeybindingText("F2");
assertEquals("Plot0", cmd.commandText);
assertEquals("F2", cmd.keybinding);
cmd = new InteractiveConsoleCommand("Plot2");
editor.addCommand(cmd);
assertEquals("Plot2", editor.getCombo().getText());
editor.setCommandText("Plot it");
editor.setKeybindingText("F1");
editor.selectComboText("Plot");
assertEquals("Plot0", editor.getCommandText());
assertEquals("F2", editor.getCommandKeybinding());
editor.selectComboText("Plot2");
editor.removeSelectedCommand();
assertEquals("Plot", editor.getCombo().getText());
final ArrayList<Object> lst = new ArrayList<>();
ICallbackListener<Object> iCallbackListener = new ICallbackListener<Object>() {
@Override
public Object call(Object obj) {
synchronized (lst) {
lst.add(1);
}
return null;
}
};
InteractiveConsoleCommand.registerOnCommandsChangedCallback(iCallbackListener);
editor.performSave();
for (int i = 0; i < 10; i++) {
synchronized (lst) {
if (lst.size() > 0) {
break;
}
}
synchronized (this) {
this.wait(50);
}
if (i == 9) {
fail("Did not get notification that the commands changed.");
}
}
InteractiveConsoleCommand.unregisterOnCommandsChangedCallback(iCallbackListener);
// Uncomment below to see results.
// goToManual(display, parent);
}
Aggregations