use of org.python.pydev.debug.pyunit.HistoryAction.HistoryMenuCreator in project Pydev by fabioz.
the class PyUnitView2TestTestWorkbench method getPyUnitViewOkCallback.
private ICallback<Boolean, Object> getPyUnitViewOkCallback(final int historySize, final int methodsAppearingInTree) {
return new ICallback<Boolean, Object>() {
@Override
public Boolean call(Object arg) {
PyUnitView view = PyUnitView.getView();
PyUnitTestRun currentTestRun = view.getCurrentTestRun();
if (currentTestRun == null) {
if (arg == THROW_ERROR) {
throw new AssertionError("currentTestRun == null");
}
return false;
}
if (!currentTestRun.getFinished()) {
if (arg == THROW_ERROR) {
throw new AssertionError("!currentTestRun.getFinished()");
}
return false;
}
Tree tree = view.getTree();
if (tree.getItemCount() != methodsAppearingInTree) {
if (arg == THROW_ERROR) {
throw new AssertionError("tree.getItemCount() " + tree.getItemCount() + "!= methodsRun " + methodsAppearingInTree);
}
return false;
}
CounterPanel counterPanel = view.getCounterPanel();
if (!counterPanel.fNumberOfErrors.getText().equals("1")) {
if (arg == THROW_ERROR) {
throw new AssertionError("!counterPanel.fNumberOfErrors.getText().equals(\"1\")");
}
return false;
}
if (!counterPanel.fNumberOfFailures.getText().equals("1")) {
if (arg == THROW_ERROR) {
throw new AssertionError("!counterPanel.fNumberOfFailures.getText().equals(\"1\")");
}
return false;
}
HistoryAction historyAction = (HistoryAction) getPyUnitViewAction(view, HistoryAction.class);
HistoryAction.HistoryMenuCreator menuCreator = (HistoryMenuCreator) historyAction.getMenuCreator();
final List<SetCurrentRunAction> actions = new ArrayList<SetCurrentRunAction>();
final List<ClearTerminatedAction> terminatedActions = new ArrayList<ClearTerminatedAction>();
IActionsMenu actionsMenu = new IActionsMenu() {
@Override
public void add(IAction action) {
if (action instanceof SetCurrentRunAction) {
actions.add((SetCurrentRunAction) action);
} else if (action instanceof ClearTerminatedAction) {
terminatedActions.add((ClearTerminatedAction) action);
}
}
};
menuCreator.fillMenuManager(actionsMenu);
if (historySize + 1 != actions.size()) {
// +1 to count for the current!
if (arg == THROW_ERROR) {
throw new AssertionError("historySize + 1 != actions.size()");
}
return false;
}
return true;
}
};
}
use of org.python.pydev.debug.pyunit.HistoryAction.HistoryMenuCreator in project Pydev by fabioz.
the class PyUnitViewTestTestWorkbench method testPyUnitView.
public void testPyUnitView() throws Exception {
PyUnitViewServerListener.TIMEOUT = 0;
PyUnitViewServerListener.JOBS_PRIORITY = Job.INTERACTIVE;
IPyUnitServer pyUnitServer = new IPyUnitServer() {
@Override
public void registerOnNotifyTest(IPyUnitServerListener pyUnitViewServerListener) {
PyUnitViewTestTestWorkbench.this.pyUnitViewServerListener = pyUnitViewServerListener;
}
@Override
public IPyUnitLaunch getPyUnitLaunch() {
return new IPyUnitLaunch() {
@Override
public void stop() {
terminated1 = true;
}
@Override
public void relaunch() {
relaunched1 = true;
}
@Override
public void relaunchTestResults(List<PyUnitTestResult> arrayList) {
}
@Override
public void relaunchTestResults(List<PyUnitTestResult> arrayList, String mode) {
}
@Override
public void fillXMLElement(Document document, Element launchElement) {
}
@Override
public ILaunchConfiguration getLaunchConfiguration() {
return null;
}
};
}
};
IPyUnitServer pyUnitServer2 = new IPyUnitServer() {
@Override
public void registerOnNotifyTest(IPyUnitServerListener pyUnitViewServerListener) {
PyUnitViewTestTestWorkbench.this.pyUnitViewServerListener = pyUnitViewServerListener;
}
@Override
public IPyUnitLaunch getPyUnitLaunch() {
return new IPyUnitLaunch() {
@Override
public void stop() {
terminated2 = true;
}
@Override
public void relaunch() {
relaunched2 = true;
}
@Override
public void relaunchTestResults(List<PyUnitTestResult> arrayList) {
}
@Override
public void relaunchTestResults(List<PyUnitTestResult> arrayList, String mode) {
}
@Override
public void fillXMLElement(Document document, Element launchElement) {
}
@Override
public ILaunchConfiguration getLaunchConfiguration() {
return null;
}
};
}
};
PyUnitViewServerListener serverListener1 = PyUnitView.registerPyUnitServer(pyUnitServer, false);
PyUnitView view = PyUnitView.getView();
assertSame(pyUnitViewServerListener, serverListener1);
CounterPanel counterPanel = view.getCounterPanel();
PyUnitProgressBar progressBar = view.getProgressBar();
notifyTestsCollected(9);
assertEquals("0 / 9", counterPanel.fNumberOfRuns.getText());
notifyTest("ok", "d:/temp/a.py", "TestCase.testMet1", "", "", "0.1");
assertSame(view.getCurrentTestRun(), serverListener1.getTestRun());
assertEquals(1, serverListener1.getTestRun().getSharedResultsList().size());
assertEquals("1 / 9", counterPanel.fNumberOfRuns.getText());
assertEquals("0", counterPanel.fNumberOfErrors.getText());
assertEquals("0", counterPanel.fNumberOfFailures.getText());
assertEquals(false, progressBar.getHasErrors());
notifyTest("fail", "d:/temp/a.py", "TestCase.testMet2", "", "", "0.3");
assertEquals("2 / 9", counterPanel.fNumberOfRuns.getText());
assertEquals("0", counterPanel.fNumberOfErrors.getText());
assertEquals("1", counterPanel.fNumberOfFailures.getText());
assertEquals(true, progressBar.getHasErrors());
notifyTest("error", "d:/temp/a.py", "TestCase.testMet2", "", "", "0.5");
assertEquals("3 / 9", counterPanel.fNumberOfRuns.getText());
assertEquals("1", counterPanel.fNumberOfErrors.getText());
assertEquals("1", counterPanel.fNumberOfFailures.getText());
assertEquals(true, progressBar.getHasErrors());
notifyFinished();
ShowOnlyFailuresAction action = (ShowOnlyFailuresAction) getPyUnitViewAction(view, ShowOnlyFailuresAction.class);
// clicking it should do this.
action.setChecked(false);
action.run();
// showing all methods (not only failures/errors)
assertTrue(!action.isChecked());
checkRun1Active(view, serverListener1);
PyUnitViewServerListener serverListener2 = PyUnitView.registerPyUnitServer(pyUnitServer2, false);
assertSame(pyUnitViewServerListener, serverListener2);
assertNotSame(pyUnitViewServerListener, serverListener1);
checkRun2Active(view, serverListener2);
view.setCurrentRun(serverListener1.getTestRun());
assertEquals(true, progressBar.getHasErrors());
view.setCurrentRun(serverListener2.getTestRun());
assertEquals(false, progressBar.getHasErrors());
executePyUnitViewAction(view, StopAction.class);
assertTrue(terminated2);
assertFalse(terminated1);
HistoryAction historyAction = (HistoryAction) getPyUnitViewAction(view, HistoryAction.class);
HistoryAction.HistoryMenuCreator menuCreator = (HistoryMenuCreator) historyAction.getMenuCreator();
final List<SetCurrentRunAction> actions = new ArrayList<SetCurrentRunAction>();
final List<ClearTerminatedAction> terminatedActions = new ArrayList<ClearTerminatedAction>();
IActionsMenu actionsMenu = new IActionsMenu() {
@Override
public void add(IAction action) {
if (action instanceof SetCurrentRunAction) {
actions.add((SetCurrentRunAction) action);
} else if (action instanceof ClearTerminatedAction) {
terminatedActions.add((ClearTerminatedAction) action);
}
}
};
menuCreator.fillMenuManager(actionsMenu);
assertEquals(2, actions.size());
actions.get(0).run();
checkRun1Active(view, serverListener1);
actions.get(1).run();
checkRun2Active(view, serverListener2);
actions.get(0).run();
checkRun1Active(view, serverListener1);
assertEquals(terminatedActions.size(), 1);
action = (ShowOnlyFailuresAction) getPyUnitViewAction(view, ShowOnlyFailuresAction.class);
assertFalse(action.isChecked());
// clicking it should do this.
action.setChecked(true);
action.run();
assertTrue(action.isChecked());
checkRun1Active(view, serverListener1, true);
actions.clear();
terminatedActions.get(0).run();
terminatedActions.clear();
menuCreator.fillMenuManager(actionsMenu);
// the other was terminated
assertEquals(1, actions.size());
assertEquals(1, terminatedActions.size());
executePyUnitViewAction(view, RelaunchAction.class);
assertTrue(relaunched2);
// goToManual();
}
Aggregations