use of com.python.pydev.analysis.actions.AnalyzeOnRequestSetter.AnalyzeOnRequestAction in project Pydev by fabioz.
the class AnalysisRequestsTestWorkbench method CheckRefreshAnalyzesFilesOnlyOnActiveEditor.
/**
* Checks what happens now if the user wants to hear only notifications on opened editors.
*
* @throws Exception
*/
public void CheckRefreshAnalyzesFilesOnlyOnActiveEditor() throws Exception {
print("----------- CheckRefreshAnalyzesFilesOnlyOnActiveEditor ---------");
// analyze all files
PyDevBuilderPreferences.setAnalyzeOnlyActiveEditor(true);
print("----------- CLOSING EDITOR ---------");
editor.close(false);
// wait a bit for the current things to clear
goToManual(TIME_FOR_ANALYSIS);
ICallback<Object, Tuple<String, SimpleNode>> parseFastDefinitionsCallback = getParseFastDefinitionsCallback();
FastDefinitionsParser.parseCallbacks.add(parseFastDefinitionsCallback);
ICallback<Object, IResource> analysisErrorCallback = getAnalysisErrorCallback();
AnalysisBuilderRunnable.analysisBuilderListeners.add(analysisErrorCallback);
try {
synchronized (lock) {
fastParsesDone.clear();
}
print("----------- Setting invalid contents ---------");
setFileContents(invalidMod1Contents);
goToIdleLoopUntilCondition(getFastModulesParsedCondition("pack1.pack2.mod1"));
// 2 seconds would be enough for errors to appear
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(getNoErrorMarkersCondition(), getMarkers());
synchronized (lock) {
fastParsesDone.clear();
}
print("----------- Setting valid contents ---------");
setFileContents(validMod1Contents);
// 2 seconds would be enough for errors to appear
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(getNoErrorMarkersCondition(), getMarkers());
assertEquals(1, fastParsesDone.size());
} finally {
FastDefinitionsParser.parseCallbacks.remove(parseFastDefinitionsCallback);
AnalysisBuilderRunnable.analysisBuilderListeners.remove(analysisErrorCallback);
}
ICallback<Object, IResource> analysisCallback = getAnalysisCallback();
AnalysisBuilderRunnable.analysisBuilderListeners.add(analysisCallback);
try {
// ok, now, let's check it
print("----------- Opening editor ---------");
resourcesAnalyzed.clear();
editor = (PyEdit) PyOpenEditor.doOpenEditor(mod1);
// in 3 seconds, 1 analysis should happen (because we've just opened the editor and the markers are only
// computed when it's opened)
goToManual(TIME_FOR_ANALYSIS);
assertEquals("Expected 1 resource analyzed. Found: " + resourcesAnalyzed, 1, resourcesAnalyzed.size());
print("----------- Setting invalid contents ---------");
setFileContents(invalidMod1Contents);
goToIdleLoopUntilCondition(get1ResourceAnalyzed(), getResourcesAnalyzed());
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(getHasSyntaxErrorMarkersCondition(mod1), getMarkers());
goToManual(TIME_FOR_ANALYSIS);
resourcesAnalyzed.clear();
print("------------- Requesting analysis -------------");
AnalyzeOnRequestAction analyzeOnRequestAction = new AnalyzeOnRequestSetter.AnalyzeOnRequestAction(editor);
analyzeOnRequestAction.run();
goToIdleLoopUntilCondition(get1ResourceAnalyzed(), getResourcesAnalyzed());
assertEquals(1, resourcesAnalyzed.size());
print("----------- Reopening editor ---------");
resourcesAnalyzed.clear();
editor.close(false);
// removes the markers when the editor is closed
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(getNoErrorMarkersCondition(), getMarkers());
editor = (PyEdit) PyOpenEditor.doOpenEditor(mod1);
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(get1ResourceAnalyzed(), getResourcesAnalyzed());
goToIdleLoopUntilCondition(getHasBothErrorMarkersCondition(), getMarkers());
print("----------- Changing editor contents and saving ---------");
resourcesAnalyzed.clear();
editor.getDocument().set(invalidMod1Contents + "\n");
editor.doSave(null);
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(get1ResourceAnalyzed(), getResourcesAnalyzed());
goToIdleLoopUntilCondition(getHasBothErrorMarkersCondition(), getMarkers());
print("----------- Changing editor input ---------");
IPath mod2Path = mod1.getFullPath().removeLastSegments(1).append("mod2.py");
mod1.copy(mod2Path, true, null);
mod2 = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(mod2Path);
editor.setInput(new FileEditorInput(mod2));
// give it some time
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(getNoErrorMarkersCondition(), getMarkers());
goToIdleLoopUntilCondition(getHasBothErrorMarkersCondition(mod2), getMarkers());
print("----------- Create new editor with same input ---------");
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
editor2 = (PyEdit) page.openEditor(editor.getEditorInput(), editor.getSite().getId(), true, IWorkbenchPage.MATCH_NONE);
// give it some time
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(getHasBothErrorMarkersCondition(mod2), getMarkers());
editor2.close(false);
editor2 = null;
goToIdleLoopUntilCondition(getHasBothErrorMarkersCondition(mod2), getMarkers());
editor.close(false);
goToManual(TIME_FOR_ANALYSIS);
goToIdleLoopUntilCondition(getNoErrorMarkersCondition(mod2), getMarkers());
// leave it open
editor = (PyEdit) PyOpenEditor.doOpenEditor(mod1);
} finally {
AnalysisBuilderRunnable.analysisBuilderListeners.remove(analysisCallback);
}
}
use of com.python.pydev.analysis.actions.AnalyzeOnRequestSetter.AnalyzeOnRequestAction in project Pydev by fabioz.
the class AnalysisRequestsTestWorkbench method testRefreshAnalyzesFiles.
public void testRefreshAnalyzesFiles() throws Exception {
editor.close(false);
// just to have any parse events consumed
goToIdleLoopUntilCondition(getInitialParsesCondition(), getParsesDone(), false);
// give it a bit more time...
goToManual(TIME_FOR_ANALYSIS);
PythonNature nature = PythonNature.getPythonNature(mod1);
AbstractAdditionalTokensInfo info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
// all modules are empty
assertEquals(new HashSet<String>(), info.getAllModulesWithTokens());
ICallback<Object, IResource> analysisCallback = getAnalysisCallback();
AnalysisBuilderRunnable.analysisBuilderListeners.add(analysisCallback);
try {
checkSetInvalidContents();
checkSetValidContents(info);
checkSetValidContentsWithFooToken(info);
checkRename(info);
checkSetValidContents(info);
// can analyze when editor is opened
resourcesAnalyzed.clear();
print("-------- Opening editor ----------");
editor = (PyEdit) PyOpenEditor.doOpenEditor(mod1);
goToIdleLoopUntilCondition(get1ResourceAnalyzed(), getResourcesAnalyzed());
assertEquals(1, resourcesAnalyzed.size());
// wait for it to complete (if it's too close it may consider it being the same analysis request even with a different time)
goToManual(TIME_FOR_ANALYSIS);
// analyze when forced
resourcesAnalyzed.clear();
AnalyzeOnRequestAction analyzeOnRequestAction = new AnalyzeOnRequestSetter.AnalyzeOnRequestAction(editor);
analyzeOnRequestAction.run();
// in 1 seconds, 1 analysis should happen
goToManual(TIME_FOR_ANALYSIS);
assertEquals(1, resourcesAnalyzed.size());
} finally {
AnalysisBuilderRunnable.analysisBuilderListeners.remove(analysisCallback);
}
CheckRefreshAnalyzesFilesOnlyOnActiveEditor();
}
Aggregations