Commit ed2f7c01 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Added test for Python console.

Added test (and mechanism to test) for Python console This test currently tests
that Python console continues to work after disconnects.

Change-Id: Ie88690cb6de75d9832375975bb4276cf5b9861b5
parent a1e6340b
......@@ -4,6 +4,12 @@ SET (TESTS_WITHOUT_BASELINES
${CMAKE_CURRENT_SOURCE_DIR}/ServerConnectDialog.xml
)
if (PARAVIEW_ENABLE_PYTHON)
set (TESTS_WITHOUT_BASELINES
${TESTS_WITHOUT_BASELINES}
${CMAKE_CURRENT_SOURCE_DIR}/TestPythonConsole.xml)
endif()
SET (TESTS_WITH_INLINE_COMPARES
${CMAKE_CURRENT_SOURCE_DIR}/TestIsoVolume.xml
${CMAKE_CURRENT_SOURCE_DIR}/LoadStateMultiView.xml
......
<?xml version="1.0" ?>
<pqevents>
<!-- This test ensures that Python Console continues to work even after
mutliple disconnects and that Connect/Disconnect from Python Console works.
-->
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menuTools" />
<pqevent object="pqClientMainWindow/menubar/menuTools" command="activate" arguments="actionToolsPythonShell" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Sphere()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Show()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Render()" />
<pqevent object="pqClientMainWindow/MainControlsToolbar/actionServerDisconnect" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/1QMessageBox0/qt_msgbox_buttonbox/1QPushButton0" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Sphere()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Show()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Render()" />
<pqevent object="pqClientMainWindow/MainControlsToolbar/actionServerDisconnect" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/1QMessageBox0/qt_msgbox_buttonbox/1QPushButton0" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Wavelet()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Show()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Render()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Disconnect()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Connect()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Sphere()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Show()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Render()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="ResetCamera()" />
<pqevent object="pqClientMainWindow/pythonDialog/splitter/verticalLayoutWidget/shellWidget/1pqConsoleWidget0" command="executeCommand" arguments="Render()" />
</pqevents>
......@@ -49,6 +49,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqCollaborationEventPlayer.h"
#include "pqColorButtonEventPlayer.h"
#include "pqColorButtonEventTranslator.h"
#include "pqConsoleWidgetEventPlayer.h"
#include "pqConsoleWidgetEventTranslator.h"
#include "pqFileDialogEventPlayer.h"
#include "pqFileDialogEventTranslator.h"
#include "pqFlatTreeViewEventPlayer.h"
......@@ -125,6 +127,8 @@ pqCoreTestUtility::pqCoreTestUtility(QObject* p) :
new pqFlatTreeViewEventTranslator(this));
this->eventTranslator()->addWidgetEventTranslator(
new pqColorButtonEventTranslator(this));
this->eventTranslator()->addWidgetEventTranslator(
new pqConsoleWidgetEventTranslator(this));
this->eventPlayer()->addWidgetEventPlayer(
new pqQVTKWidgetEventPlayer(this));
......@@ -136,6 +140,8 @@ pqCoreTestUtility::pqCoreTestUtility(QObject* p) :
new pqColorButtonEventPlayer(this));
this->eventPlayer()->addWidgetEventPlayer(
new pqCollaborationEventPlayer(this));
this->eventPlayer()->addWidgetEventPlayer(
new pqConsoleWidgetEventPlayer(this));
}
//-----------------------------------------------------------------------------
......
......@@ -57,6 +57,10 @@ set(Module_SRCS
pqConnect.h
pqConsoleWidget.cxx
pqConsoleWidget.h
pqConsoleWidgetEventPlayer.cxx
pqConsoleWidgetEventPlayer.h
pqConsoleWidgetEventTranslator.cxx
pqConsoleWidgetEventTranslator.h
pqDelimitedTextParser.cxx
pqDelimitedTextParser.h
pqDoubleRangeDialog.cxx
......@@ -130,6 +134,8 @@ QT4_WRAP_CPP(QtWidgets_MOC_SOURCES
pqCollapsedGroup.h
pqColorChooserButton.h
pqColorTableModel.h
pqConsoleWidgetEventPlayer.h
pqConsoleWidgetEventTranslator.h
pqConsoleWidget.h
pqDelimitedTextParser.h
pqDoubleRangeDialog.h
......
......@@ -464,6 +464,18 @@ void pqConsoleWidget::printCommand(const QString& cmd)
this->Implementation->updateCommandBuffer();
}
//-----------------------------------------------------------------------------
void pqConsoleWidget::printAndExecuteCommand(const QString& text)
{
this->printCommand(text);
QTextCursor text_cursor = this->Implementation->textCursor();
text_cursor.setPosition(this->Implementation->documentEnd());
this->Implementation->setTextCursor(text_cursor);
this->Implementation->internalExecuteCommand();
}
//-----------------------------------------------------------------------------
void pqConsoleWidget::prompt(const QString& text)
{
......
......@@ -102,6 +102,12 @@ private:
class pqImplementation;
pqImplementation* const Implementation;
friend class pqImplementation;
friend class pqConsoleWidgetEventPlayer;
/// Prints and executes the command. Used by pqConsoleWidgetEventPlayer for
/// text playback.
void printAndExecuteCommand(const QString& text);
};
......
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqConsoleWidgetEventPlayer.h"
#include "pqConsoleWidget.h"
#include <QtDebug>
//-----------------------------------------------------------------------------
pqConsoleWidgetEventPlayer::pqConsoleWidgetEventPlayer(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqConsoleWidgetEventPlayer::~pqConsoleWidgetEventPlayer()
{
}
//-----------------------------------------------------------------------------
bool pqConsoleWidgetEventPlayer::playEvent(QObject* target,
const QString& cmd, const QString& args, bool& errorFlag)
{
pqConsoleWidget* widget = qobject_cast<pqConsoleWidget*>(target);
if (!widget)
{
return false;
}
if (cmd == "executeCommand")
{
widget->printAndExecuteCommand(args);
return true;
}
qCritical() << "Unknown command for pqConsoleWidget : "
<< target << " " << cmd << " " << args;
errorFlag = true;
return true;
}
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef __pqConsoleWidgetEventPlayer_h
#define __pqConsoleWidgetEventPlayer_h
#include "pqWidgetEventPlayer.h"
#include "pqWidgetsModule.h" // needed for EXPORT macro.
/// pqConsoleWidgetEventPlayer is used to play back test commands recorded by
/// pqConsoleWidgetEventTranslator for pqConsoleWidget.
class PQWIDGETS_EXPORT pqConsoleWidgetEventPlayer : public pqWidgetEventPlayer
{
Q_OBJECT
typedef pqWidgetEventPlayer Superclass;
public:
pqConsoleWidgetEventPlayer(QObject* parent=0);
virtual ~pqConsoleWidgetEventPlayer();
/// Callback to play a command.
virtual bool playEvent(QObject* target,
const QString& cmd, const QString& args, bool& errorFlag);
private:
Q_DISABLE_COPY(pqConsoleWidgetEventPlayer)
};
#endif
/*=========================================================================
Program: ParaView
Module: pqConsoleWidgetEventTranslator.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqConsoleWidgetEventTranslator.h"
#include "pqConsoleWidget.h"
#include <QEvent>
//-----------------------------------------------------------------------------
pqConsoleWidgetEventTranslator::pqConsoleWidgetEventTranslator(QObject* parentObject)
: Superclass(parentObject)
{
}
//-----------------------------------------------------------------------------
pqConsoleWidgetEventTranslator::~pqConsoleWidgetEventTranslator()
{
}
//-----------------------------------------------------------------------------
bool pqConsoleWidgetEventTranslator::translateEvent(
QObject* target, QEvent* qtevent, bool& errorFlag)
{
// Capture inputs for pqConsoleWidget and all its children
pqConsoleWidget* object = NULL;
for (QObject* current = target; current != NULL; current = current->parent())
{
object = qobject_cast<pqConsoleWidget*>(current);
if (object)
{
break;
}
}
if (!object)
{
return false;
}
if (qtevent->type() == QEvent::FocusIn)
{
if (this->CurrentObject)
{
QObject::disconnect(this->CurrentObject, NULL, this, NULL);
}
this->CurrentObject = object;
QObject::connect(
this->CurrentObject, SIGNAL(executeCommand(const QString&)),
this, SLOT(recordCommand(const QString&)));
}
return true;
}
//-----------------------------------------------------------------------------
void pqConsoleWidgetEventTranslator::recordCommand(const QString& text)
{
emit this->recordEvent(this->CurrentObject, "executeCommand", text);
}
/*=========================================================================
Program: ParaView
Module: pqConsoleWidgetEventTranslator.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef __pqConsoleWidgetEventTranslator_h
#define __pqConsoleWidgetEventTranslator_h
#include "pqWidgetEventTranslator.h"
#include "pqWidgetsModule.h" // needed for EXPORT macro.
#include <QPointer> // needed for QPointer
class pqConsoleWidget;
/// pqConsoleWidgetEventTranslator is used to record events from pqConsoleWidget
/// testing.
class PQWIDGETS_EXPORT pqConsoleWidgetEventTranslator :
public pqWidgetEventTranslator
{
Q_OBJECT
typedef pqWidgetEventTranslator Superclass;
public:
pqConsoleWidgetEventTranslator(QObject* parent=0);
virtual ~pqConsoleWidgetEventTranslator();
/// Translate the event, if possible.
virtual bool translateEvent(QObject* target, QEvent* qtevent, bool& errorFlag);
protected slots:
void recordCommand(const QString& text);
private:
Q_DISABLE_COPY(pqConsoleWidgetEventTranslator)
QPointer<pqConsoleWidget> CurrentObject;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment