diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java index 436eaf00eb..2bc0376e65 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java @@ -45,6 +45,7 @@ import org.python.pydev.shared_core.callbacks.ICallback; import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle; import org.python.pydev.shared_core.code_completion.IPyCompletionProposal; +import org.python.pydev.shared_core.image.DummyImageCache; import org.python.pydev.shared_core.image.IImageCache; import org.python.pydev.shared_core.image.UIConstants; import org.python.pydev.shared_core.string.FullRepIterable; @@ -83,6 +84,9 @@ public static List getTddProps(PySelection ps, IImage if (ret == null) { ret = new ArrayList(); } + if (imageCache == null) { + imageCache = new DummyImageCache(); + } //Additional option: Generate markers for 'self.' accesses int lineOfOffset = ps.getLineOfOffset(offset); String lineContents = ps.getLine(lineOfOffset); diff --git a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/image/DummyImageCache.java b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/image/DummyImageCache.java new file mode 100644 index 0000000000..98fbc503c9 --- /dev/null +++ b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/image/DummyImageCache.java @@ -0,0 +1,47 @@ +package org.python.pydev.shared_core.image; + +public class DummyImageCache implements IImageCache { + + @Override + public IImageHandle get(String key) { + return null; + } + + @Override + public IImageHandle getImageDecorated(String key, String decoration) { + return null; + } + + @Override + public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation) { + return null; + } + + @Override + public IImageDescriptor getDescriptor(String projectIcon) { + return null; + } + + @Override + public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation, + String secondDecoration, int secondDecorationLocation) { + return new IImageHandle() { + + @Override + public Object getImageData() { + return null; + } + + @Override + public Object getImage() { + return null; + } + }; + } + + @Override + public IImageHandle getStringDecorated(String key, String stringToAddToDecoration) { + return null; + } + +} diff --git a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/testutils/TestUtils.java b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/testutils/TestUtils.java index 6db64be776..2b5c2d1897 100644 --- a/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/testutils/TestUtils.java +++ b/plugins/org.python.pydev.shared_core/src/org/python/pydev/shared_core/testutils/TestUtils.java @@ -15,7 +15,7 @@ import java.util.List; import org.eclipse.jface.text.IDocument; -import org.python.pydev.shared_core.callbacks.ICallback; +import org.python.pydev.shared_core.callbacks.ICallback0; import org.python.pydev.shared_core.partitioner.IToken; import org.python.pydev.shared_core.partitioner.ITokenScanner; import org.python.pydev.shared_core.string.FastStringBuffer; @@ -24,14 +24,24 @@ public class TestUtils { private final static Object lock = new Object(); + public static void waitForCondition(ICallback0 call) { + // just an alias + waitUntilCondition(call); + } + + public static void waitUntilCondition(ICallback0 call) { + // default (5 seconds) + waitUntilCondition(call, 5000); + } + /** * If callback returns null, stop the loop, otherwise keep looping (until timeout is reached). */ - public static void waitUntilCondition(ICallback call) { + public static void waitUntilCondition(ICallback0 call, int timeout) { long currentTimeMillis = System.currentTimeMillis(); String msg = null; while (System.currentTimeMillis() < currentTimeMillis + 5000) { //at most 5 seconds - msg = call.call(null); + msg = call.call(); if (msg == null) { return; } diff --git a/plugins/org.python.pydev.shared_core/tests/org/python/pydev/shared_core/path_watch/PathWatchTest.java b/plugins/org.python.pydev.shared_core/tests/org/python/pydev/shared_core/path_watch/PathWatchTest.java index eae6caf08e..993adeae36 100644 --- a/plugins/org.python.pydev.shared_core/tests/org/python/pydev/shared_core/path_watch/PathWatchTest.java +++ b/plugins/org.python.pydev.shared_core/tests/org/python/pydev/shared_core/path_watch/PathWatchTest.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.Set; -import org.python.pydev.shared_core.callbacks.ICallback; +import org.python.pydev.shared_core.callbacks.ICallback0; import org.python.pydev.shared_core.callbacks.ListenerList; import org.python.pydev.shared_core.io.FileUtils; import org.python.pydev.shared_core.string.FastStringBuffer; @@ -291,10 +291,10 @@ public void testPathWatchDirs4() throws Exception { fail("Not expecting any addition (we don't track changes recursively)."); } - // waitUntilCondition(new ICallback() { + // waitUntilCondition(new ICallback0() { // // @Override - // public String call(Object arg) { + // public String call() { // if (getChangeHappened()) { // return null; // } @@ -344,10 +344,10 @@ public void added(File file) { FileUtils.writeStrToFile("FILE1", new File(baseDir, "f" + i + ".txt")); } - waitUntilCondition(new ICallback() { + waitUntilCondition(new ICallback0() { @Override - public String call(Object arg) { + public String call() { Tuple[] array = createChangesArray(changes); HashSet> set = new HashSet<>(Arrays.asList(array)); @@ -374,10 +374,10 @@ public String call(Object arg) { f.delete(); } } - waitUntilCondition(new ICallback() { + waitUntilCondition(new ICallback0() { @Override - public String call(Object arg) { + public String call() { int foundRemovals = 0; Tuple[] array = createChangesArray(changes); @@ -399,10 +399,10 @@ public String call(Object arg) { pathWatch.log.append("--- Will delete base dir ---\n"); assertTrue(baseDir.delete()); - waitUntilCondition(new ICallback() { + waitUntilCondition(new ICallback0() { @Override - public String call(Object arg) { + public String call() { Tuple[] array = createChangesArray(changes); @@ -457,7 +457,7 @@ public String call(Object arg) { assertEquals(0, changes.size()); } - private void waitUntilCondition(ICallback call) { + private void waitUntilCondition(ICallback0 call) { try { TestUtils.waitUntilCondition(call); } catch (AssertionError e1) { diff --git a/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/system_info_builder/SyncSystemModulesManagerTest.java b/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/system_info_builder/SyncSystemModulesManagerTest.java index 87b251fd2b..66789a3da2 100644 --- a/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/system_info_builder/SyncSystemModulesManagerTest.java +++ b/plugins/org.python.pydev/tests_analysis/com/python/pydev/analysis/system_info_builder/SyncSystemModulesManagerTest.java @@ -33,8 +33,8 @@ import org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate; import org.python.pydev.ast.codecompletion.revisited.ProjectModulesManager; import org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager; -import org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManagerScheduler; import org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager.PythonpathChange; +import org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManagerScheduler; import org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManagerScheduler.IInfoTrackerListener; import org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManagerScheduler.InfoTracker; import org.python.pydev.ast.interpreter_managers.InterpreterInfo; @@ -48,7 +48,7 @@ import org.python.pydev.core.MisconfigurationException; import org.python.pydev.core.TestDependent; import org.python.pydev.plugin.PydevTestUtils; -import org.python.pydev.shared_core.callbacks.ICallback; +import org.python.pydev.shared_core.callbacks.ICallback0; import org.python.pydev.shared_core.io.FileUtils; import org.python.pydev.shared_core.preferences.InMemoryEclipsePreferences; import org.python.pydev.shared_core.string.StringUtils; @@ -247,10 +247,10 @@ public void onChangedIInterpreterInfo(InfoTracker infoTracker, File file) { } final File module4File = new File(libDir, "module4.py"); FileUtils.writeStrToFile("class Module3:pass", module4File); - TestUtils.waitUntilCondition(new ICallback() { + TestUtils.waitUntilCondition(new ICallback0() { @Override - public String call(Object arg) { + public String call() { if (changes.contains(module4File)) { return null; } @@ -261,10 +261,10 @@ public String call(Object arg) { changes.clear(); final File myPthFile = new File(libDir, "my.pth"); FileUtils.writeStrToFile("./setuptools-1.1.6-py2.6.egg", myPthFile); - TestUtils.waitUntilCondition(new ICallback() { + TestUtils.waitUntilCondition(new ICallback0() { @Override - public String call(Object arg) { + public String call() { if (changes.contains(myPthFile)) { return null; } diff --git a/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/PythonCompletionWithBuiltinsTest.java b/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/PythonCompletionWithBuiltinsTest.java index e8d86c9a16..a038821aa4 100644 --- a/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/PythonCompletionWithBuiltinsTest.java +++ b/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/PythonCompletionWithBuiltinsTest.java @@ -44,6 +44,7 @@ import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle; import org.python.pydev.shared_core.io.FileUtils; import org.python.pydev.shared_core.string.StringUtils; +import org.python.pydev.shared_core.testutils.TestUtils; import junit.framework.AssertionFailedError; @@ -631,15 +632,20 @@ public void testBuiltinKnownReturns1() throws Exception { } public void testBuiltinCached() throws Exception { - IModule module = nature.getAstManager().getModule("_bisect", nature, true, new BaseModuleRequest(false)); - assertTrue("Expected CompiledModule. Found: " + module, module instanceof CompiledModule); + final IModule moduleBisect = nature.getAstManager().getModule("_bisect", nature, true, + new BaseModuleRequest(false)); + assertTrue("Expected CompiledModule. Found: " + moduleBisect, moduleBisect instanceof CompiledModule); + ISystemModulesManager systemModulesManager = nature.getAstManager().getModulesManager() .getSystemModulesManager(); RunnableAsJobsPoolThread.getSingleton().waitToFinishCurrent(); - File file = systemModulesManager.getCompiledModuleCacheFile(module.getName()); - assertTrue(file.exists()); - module = nature.getAstManager().getModule("_bisect.foo", nature, true, new BaseModuleRequest(false)); + TestUtils.waitForCondition(() -> { + File file = systemModulesManager.getCompiledModuleCacheFile(moduleBisect.getName()); + return file.exists() ? null : "File: " + file + " does not exist."; + }); + + IModule module = nature.getAstManager().getModule("_bisect.foo", nature, true, new BaseModuleRequest(false)); assertNull(module); module = nature.getAstManager().getModule("os", nature, true, new BaseModuleRequest(false));