Skip to content

Commit

Permalink
wip7
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 21, 2024
1 parent a8706d5 commit da8301b
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,6 +84,9 @@ public static List<ICompletionProposalHandle> getTddProps(PySelection ps, IImage
if (ret == null) {
ret = new ArrayList<ICompletionProposalHandle>();
}
if (imageCache == null) {
imageCache = new DummyImageCache();
}
//Additional option: Generate markers for 'self.' accesses
int lineOfOffset = ps.getLineOfOffset(offset);
String lineContents = ps.getLine(lineOfOffset);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,14 +24,24 @@ public class TestUtils {

private final static Object lock = new Object();

public static void waitForCondition(ICallback0<String> call) {
// just an alias
waitUntilCondition(call);
}

public static void waitUntilCondition(ICallback0<String> 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<String, Object> call) {
public static void waitUntilCondition(ICallback0<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -291,10 +291,10 @@ public void testPathWatchDirs4() throws Exception {
fail("Not expecting any addition (we don't track changes recursively).");
}

// waitUntilCondition(new ICallback<String, Object>() {
// waitUntilCondition(new ICallback0<String>() {
//
// @Override
// public String call(Object arg) {
// public String call() {
// if (getChangeHappened()) {
// return null;
// }
Expand Down Expand Up @@ -344,10 +344,10 @@ public void added(File file) {
FileUtils.writeStrToFile("FILE1", new File(baseDir, "f" + i + ".txt"));
}

waitUntilCondition(new ICallback<String, Object>() {
waitUntilCondition(new ICallback0<String>() {

@Override
public String call(Object arg) {
public String call() {
Tuple<String, File>[] array = createChangesArray(changes);

HashSet<Tuple<String, File>> set = new HashSet<>(Arrays.asList(array));
Expand All @@ -374,10 +374,10 @@ public String call(Object arg) {
f.delete();
}
}
waitUntilCondition(new ICallback<String, Object>() {
waitUntilCondition(new ICallback0<String>() {

@Override
public String call(Object arg) {
public String call() {

int foundRemovals = 0;
Tuple<String, File>[] array = createChangesArray(changes);
Expand All @@ -399,10 +399,10 @@ public String call(Object arg) {
pathWatch.log.append("--- Will delete base dir ---\n");
assertTrue(baseDir.delete());

waitUntilCondition(new ICallback<String, Object>() {
waitUntilCondition(new ICallback0<String>() {

@Override
public String call(Object arg) {
public String call() {

Tuple<String, File>[] array = createChangesArray(changes);

Expand Down Expand Up @@ -457,7 +457,7 @@ public String call(Object arg) {
assertEquals(0, changes.size());
}

private void waitUntilCondition(ICallback<String, Object> call) {
private void waitUntilCondition(ICallback0<String> call) {
try {
TestUtils.waitUntilCondition(call);
} catch (AssertionError e1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String, Object>() {
TestUtils.waitUntilCondition(new ICallback0<String>() {

@Override
public String call(Object arg) {
public String call() {
if (changes.contains(module4File)) {
return null;
}
Expand All @@ -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<String, Object>() {
TestUtils.waitUntilCondition(new ICallback0<String>() {

@Override
public String call(Object arg) {
public String call() {
if (changes.contains(myPthFile)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit da8301b

Please sign in to comment.