Commit b68b0af5 authored by Alexander Semke's avatar Alexander Semke
Browse files

More debug ouput in the python test to understand the failure on CI and more...

More debug ouput in the python test to understand the failure on CI and more code cleanup in various files.
parent 257c3ef2
Pipeline #152809 passed with stage
in 5 minutes and 21 seconds
......@@ -28,12 +28,7 @@
using namespace Cantor;
JuliaSession::JuliaSession(Cantor::Backend *backend)
: Session(backend)
, m_process(nullptr)
, m_interface(nullptr)
, m_isIntegratedPlotsEnabled(false)
, m_isIntegratedPlotsSettingsEnabled(false)
JuliaSession::JuliaSession(Cantor::Backend* backend) : Session(backend)
{
setVariableModel(new JuliaVariableModel(this));
}
......@@ -102,9 +97,8 @@ void JuliaSession::login()
return;
}
const QDBusReply<int> &reply = m_interface->call(
QString::fromLatin1("login"),
JuliaSettings::self()->replPath().path()
const QDBusReply<int> &reply = m_interface->call(QLatin1String("login"),
JuliaSettings::self()->replPath().path()
);
if (reply.isValid())
{
......@@ -195,23 +189,20 @@ void JuliaSession::interrupt()
}
qDebug()<<"interrupting " << expressionQueue().first()->command();
foreach (Cantor::Expression* expression, expressionQueue())
for(auto* expression : expressionQueue())
expression->setStatus(Cantor::Expression::Interrupted);
expressionQueue().clear();
changeStatus(Cantor::Session::Done);
}
Cantor::Expression *JuliaSession::evaluateExpression(
const QString &cmd,
Cantor::Expression::FinishingBehavior behave,
bool internal)
Cantor::Expression *JuliaSession::evaluateExpression(const QString& cmd, Cantor::Expression::FinishingBehavior behave, bool internal)
{
if (!internal)
updateGraphicPackagesFromSettings();
JuliaExpression *expr = new JuliaExpression(this, internal);
auto* expr = new JuliaExpression(this, internal);
expr->setFinishingBehavior(behave);
expr->setCommand(cmd);
expr->evaluate();
......@@ -219,14 +210,12 @@ Cantor::Expression *JuliaSession::evaluateExpression(
return expr;
}
Cantor::CompletionObject *JuliaSession::completionFor(
const QString &command,
int index)
Cantor::CompletionObject* JuliaSession::completionFor(const QString &command, int index)
{
return new JuliaCompletionObject(command, index, this);
}
QSyntaxHighlighter *JuliaSession::syntaxHighlighter(QObject *parent)
QSyntaxHighlighter* JuliaSession::syntaxHighlighter(QObject *parent)
{
return new JuliaHighlighter(parent, this);
}
......@@ -259,11 +248,9 @@ void JuliaSession::reportServerProcessError(QProcess::ProcessError serverError)
case QProcess::Crashed:
emit error(i18n("Julia process stopped working."));
break;
case QProcess::FailedToStart:
emit error(i18n("Failed to start Julia process."));
break;
default:
emit error(i18n("Communication with Julia process failed for unknown reasons."));
break;
......@@ -272,10 +259,9 @@ void JuliaSession::reportServerProcessError(QProcess::ProcessError serverError)
reportSessionCrash();
}
void JuliaSession::runFirstExpression()
{
Cantor::Expression* expr = expressionQueue().first();
auto* expr = expressionQueue().first();
expr->setStatus(Cantor::Expression::Computing);
runJuliaCommandAsync(expr->internalCommand());
......@@ -304,7 +290,6 @@ bool JuliaSession::getWasException()
return reply.isValid() && reply.value();
}
QString JuliaSession::plotFilePrefixPath() const
{
return m_plotFilePrefixPath;
......
......@@ -83,16 +83,16 @@ private Q_SLOTS:
void reportServerProcessError(QProcess::ProcessError serverError);
private:
KProcess *m_process; //< process to run JuliaServer inside
QDBusInterface *m_interface; //< interface to JuliaServer
KProcess* m_process{nullptr}; //< process to run JuliaServer inside
QDBusInterface* m_interface{nullptr}; //< interface to JuliaServer
/// Cache to speedup modules whos calls
QMap<QString, QString> m_whos_cache;
/// Variables for handling plot integration: settings value and real state
QString m_plotFilePrefixPath;
bool m_isIntegratedPlotsEnabled;
bool m_isIntegratedPlotsSettingsEnabled;
bool m_isIntegratedPlotsEnabled{false};
bool m_isIntegratedPlotsSettingsEnabled{false};
void runFirstExpression() override;
......
......@@ -27,7 +27,7 @@ QString TestMaxima::backendName()
void TestMaxima::testSimpleCommand()
{
Cantor::Expression* e=evalExp( QLatin1String("2+2") );
auto* e=evalExp( QLatin1String("2+2") );
QVERIFY( e!=nullptr );
QVERIFY( e->result()!=nullptr );
......@@ -37,7 +37,7 @@ void TestMaxima::testSimpleCommand()
void TestMaxima::testMultilineCommand()
{
Cantor::Expression* e = evalExp( QLatin1String("2+2;3+3") );
auto* e = evalExp( QLatin1String("2+2;3+3") );
QVERIFY(e != nullptr);
QVERIFY(e->results().size() == 2);
......@@ -55,7 +55,7 @@ void TestMaxima::testPlot()
QSKIP("gnuplot not found, maxima needs it for plotting", SkipSingle);
}
Cantor::Expression* e=evalExp( QLatin1String("plot2d(sin(x), [x, -10,10])") );
auto* e=evalExp( QLatin1String("plot2d(sin(x), [x, -10,10])") );
QVERIFY( e!=nullptr );
QVERIFY( e->result()!=nullptr );
......@@ -77,7 +77,7 @@ void TestMaxima::testPlotWithAnotherTextResults()
QSKIP("gnuplot not found, maxima needs it for plotting", SkipSingle);
}
Cantor::Expression* e=evalExp( QLatin1String(
auto* e=evalExp( QLatin1String(
"2*2; \n"
"plot2d(sin(x), [x, -10,10]); \n"
"4*4;"
......@@ -100,7 +100,7 @@ void TestMaxima::testPlotWithAnotherTextResults()
void TestMaxima::testInvalidSyntax()
{
Cantor::Expression* e=evalExp( QLatin1String("2+2*(") );
auto* e=evalExp( QLatin1String("2+2*(") );
QVERIFY( e!=nullptr );
QVERIFY( e->status()==Cantor::Expression::Error );
......@@ -144,7 +144,7 @@ void TestMaxima::testWarning02()
void TestMaxima::testExprNumbering()
{
Cantor::Expression* e=evalExp( QLatin1String("kill(labels)") ); //first reset the labels
auto* e=evalExp( QLatin1String("kill(labels)") ); //first reset the labels
e=evalExp( QLatin1String("2+2") );
QVERIFY( e!=nullptr );
......@@ -162,9 +162,9 @@ void TestMaxima::testCommandQueue()
//only wait for the last Expression to return, so the queue gets
//actually filled
Cantor::Expression* e1=session()->evaluateExpression(QLatin1String("0+1"));
Cantor::Expression* e2=session()->evaluateExpression(QLatin1String("1+1"));
Cantor::Expression* e3=evalExp(QLatin1String("1+2"));
auto* e1=session()->evaluateExpression(QLatin1String("0+1"));
auto* e2=session()->evaluateExpression(QLatin1String("1+1"));
auto* e3=evalExp(QLatin1String("1+2"));
QVERIFY(e1!=nullptr);
QVERIFY(e2!=nullptr);
......@@ -181,7 +181,7 @@ void TestMaxima::testCommandQueue()
void TestMaxima::testSimpleExpressionWithComment()
{
Cantor::Expression* e=evalExp(QLatin1String("/*this is a comment*/2+2"));
auto* e=evalExp(QLatin1String("/*this is a comment*/2+2"));
QVERIFY(e!=nullptr);
QVERIFY(e->result()!=nullptr);
......@@ -190,14 +190,14 @@ void TestMaxima::testSimpleExpressionWithComment()
void TestMaxima::testCommentExpression()
{
Cantor::Expression* e=evalExp(QLatin1String("/*this is a comment*/"));
auto* e=evalExp(QLatin1String("/*this is a comment*/"));
QVERIFY(e!=nullptr);
QVERIFY(e->result()==nullptr||e->result()->data().toString().isEmpty());
}
void TestMaxima::testNestedComment()
{
Cantor::Expression* e=evalExp(QLatin1String("/*/*this is still a comment*/*/2+2/*still/*a*/comment*//**/"));
auto* e=evalExp(QLatin1String("/*/*this is still a comment*/*/2+2/*still/*a*/comment*//**/"));
QVERIFY(e!=nullptr);
QVERIFY(e->result()!=nullptr);
......@@ -206,7 +206,7 @@ void TestMaxima::testNestedComment()
void TestMaxima::testUnmatchedComment()
{
Cantor::Expression* e=evalExp(QLatin1String("/*this comment doesn't end here!"));
auto* e=evalExp(QLatin1String("/*this comment doesn't end here!"));
QVERIFY(e!=nullptr);
QVERIFY(e->result()==nullptr);
QVERIFY(e->status()==Cantor::Expression::Error);
......@@ -214,7 +214,7 @@ void TestMaxima::testUnmatchedComment()
void TestMaxima::testInvalidAssignment()
{
Cantor::Expression* e=evalExp(QLatin1String("0:a"));
auto* e=evalExp(QLatin1String("0:a"));
QVERIFY(e!=nullptr);
//QVERIFY(e->result()==0);
//QVERIFY(e->status()==Cantor::Expression::Error);
......@@ -223,7 +223,7 @@ void TestMaxima::testInvalidAssignment()
waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status)));
//make sure we didn't screw up the session
Cantor::Expression* e2=evalExp(QLatin1String("2+2"));
auto* e2=evalExp(QLatin1String("2+2"));
QVERIFY(e2!=nullptr);
QVERIFY(e2->result()!=nullptr);
......@@ -232,7 +232,7 @@ void TestMaxima::testInvalidAssignment()
void TestMaxima::testInformationRequest()
{
Cantor::Expression* e=session()->evaluateExpression(QLatin1String("integrate(x^n,x)"));
auto* e=session()->evaluateExpression(QLatin1String("integrate(x^n,x)"));
QVERIFY(e!=nullptr);
waitForSignal(e, SIGNAL(needsAdditionalInformation(QString)));
e->addInformation(QLatin1String("N"));
......@@ -270,7 +270,7 @@ void TestMaxima::testCompletion()
void TestMaxima::testHelpRequest()
{
//execute "??print"
Cantor::Expression* e = session()->evaluateExpression(QLatin1String("??print"));
auto* e = session()->evaluateExpression(QLatin1String("??print"));
QVERIFY(e != nullptr);
//help result will be shown, but maxima still expects further input
......@@ -278,6 +278,7 @@ void TestMaxima::testHelpRequest()
if (e->status() == Cantor::Expression::Computing)
waitForSignal(e, SIGNAL(statusChanged(Cantor::Expression::Status)));
QVERIFY(e->status() != Cantor::Expression::Done);
QVERIFY(e->results().size() == 1); //two results, the warning and the actual result of the calculation
//ask for help for the first flag of the print command
e->addInformation(QLatin1String("0"));
......@@ -287,6 +288,7 @@ void TestMaxima::testHelpRequest()
if (e->status() == Cantor::Expression::Computing)
waitForSignal(e, SIGNAL(statusChanged(Cantor::Expression::Status)));
QVERIFY(e->status() == Cantor::Expression::Done);
QVERIFY(e->results().size() == 2); //two results, the warning and the actual result of the calculation
}
void TestMaxima::testVariableModel()
......@@ -294,9 +296,9 @@ void TestMaxima::testVariableModel()
QAbstractItemModel* model = session()->variableModel();
QVERIFY(model != nullptr);
Cantor::Expression* e1=evalExp(QLatin1String("a: 15"));
Cantor::Expression* e2=evalExp(QLatin1String("a: 15; b: \"Hello, world!\""));
Cantor::Expression* e3=evalExp(QLatin1String("l: [1,2,3]"));
auto* e1=evalExp(QLatin1String("a: 15"));
auto* e2=evalExp(QLatin1String("a: 15; b: \"Hello, world!\""));
auto* e3=evalExp(QLatin1String("l: [1,2,3]"));
QVERIFY(e1!=nullptr);
QVERIFY(e2!=nullptr);
QVERIFY(e3!=nullptr);
......@@ -363,13 +365,13 @@ void TestMaxima::testLoginLogout()
void TestMaxima::testRestartWhileRunning()
{
Cantor::Expression* e1=session()->evaluateExpression(QLatin1String(":lisp (sleep 5)"));
auto* e1=session()->evaluateExpression(QLatin1String(":lisp (sleep 5)"));
session()->logout();
QCOMPARE(e1->status(), Cantor::Expression::Interrupted);
session()->login();
Cantor::Expression* e2=evalExp( QLatin1String("2+2") );
auto* e2=evalExp( QLatin1String("2+2") );
QVERIFY(e2 != nullptr);
QVERIFY(e2->result() != nullptr);
......
......@@ -30,15 +30,11 @@
#include <signal.h>
#endif
const QChar recordSep(30);
const QChar unitSep(31);
const QChar messageEnd = 29;
PythonSession::PythonSession(Cantor::Backend* backend)
: Session(backend)
, m_process(nullptr)
, m_plotFileCounter(0)
PythonSession::PythonSession(Cantor::Backend* backend) : Session(backend)
{
setVariableModel(new PythonVariableModel(this));
}
......@@ -126,6 +122,7 @@ void PythonSession::logout()
if (m_process->exitStatus() != QProcess::CrashExit && m_process->error() != QProcess::WriteError)
sendCommand(QLatin1String("exit"));
if(m_process->state() == QProcess::Running && !m_process->waitForFinished(1000))
{
disconnect(m_process, &QProcess::errorOccurred, this, &PythonSession::reportServerProcessError);
......@@ -183,9 +180,6 @@ Cantor::Expression* PythonSession::evaluateExpression(const QString& cmd, Cantor
qDebug() << "evaluating: " << cmd;
auto* expr = new PythonExpression(this, internal);
changeStatus(Cantor::Session::Running);
expr->setFinishingBehavior(behave);
expr->setCommand(cmd);
expr->evaluate();
......@@ -241,6 +235,7 @@ void PythonSession::readOutput()
if (!m_output.contains(messageEnd))
return;
const QStringList packages = m_output.split(messageEnd, QString::SkipEmptyParts);
if (m_output.endsWith(messageEnd))
m_output.clear();
......@@ -323,7 +318,7 @@ void PythonSession::updateGraphicPackagesFromSettings()
else if (val == PythonSettings::EnumChoosenGraphicPackage::plotly)
searchId = QLatin1String("plotly");
for (Cantor::GraphicPackage& package : backend()->availableGraphicPackages())
for (const auto& package : backend()->availableGraphicPackages())
{
if (package.id() == searchId)
{
......@@ -343,7 +338,6 @@ void PythonSession::updateGraphicPackagesFromSettings()
QString PythonSession::graphicPackageErrorMessage(QString packageId) const
{
Q_ASSERT(PythonSettings::EnumChoosenGraphicPackage::COUNT == 3);
if (packageId == QLatin1String("matplotlib"))
{
return i18n(
......
......@@ -9,14 +9,13 @@
#include "session.h"
#include <QStringList>
#include <QUrl>
#include <QProcess>
class PythonSession : public Cantor::Session
{
Q_OBJECT
public:
PythonSession(Cantor::Backend* backend);
PythonSession(Cantor::Backend*);
~PythonSession() override;
void login() override;
......@@ -27,21 +26,21 @@ class PythonSession : public Cantor::Session
Cantor::Expression* evaluateExpression(const QString& command, Cantor::Expression::FinishingBehavior behave = Cantor::Expression::FinishingBehavior::DoNotDelete, bool internal = false) override;
Cantor::CompletionObject* completionFor(const QString& command, int index=-1) override;
QSyntaxHighlighter* syntaxHighlighter(QObject* parent) override;
void setWorksheetPath(const QString& path) override;
void setWorksheetPath(const QString&) override;
QString plotFilePrefixPath();
int& plotFileCounter();
private:
QProcess* m_process;
QProcess* m_process{nullptr};
QString m_worksheetPath;
QString m_output;
QString m_plotFilePrefixPath;
int m_plotFileCounter;
int m_plotFileCounter{0};
private Q_SLOT:
void readOutput();
void reportServerProcessError(QProcess::ProcessError serverError);
void reportServerProcessError(QProcess::ProcessError);
private:
void runFirstExpression() override;
......
......@@ -310,10 +310,12 @@ void TestPython3::testInterrupt()
auto* e = evalExp(QLatin1String("2+2"));
QVERIFY(e != nullptr);
qDebug()<<"### session status 1 " << session()->status();
qDebug()<<"### expression status 1 " << e->status();
if (session()->status() == Cantor::Session::Running)
waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status)));
qDebug()<<"### session status 2 " << session()->status();
qDebug()<<"### expression status 2 " << e->status();
QCOMPARE(e->status(), Cantor::Expression::Done);
QVERIFY(e->result());
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2017-2021 Alexander Semke <alexander.semke@web.de>
SPDX-FileCopyrightText: 2017-2022 Alexander Semke <alexander.semke@web.de>
SPDX-FileCopyrightText: 2019 Sirgienko Nikita <warquark@gmail.com>
*/
......@@ -45,10 +45,8 @@
#include <QPrintDialog>
#include <QProgressDialog>
#include <QTextStream>
#include <QTextEdit>
#include <QTimer>
#include <QRegularExpression>
#include <QComboBox>
//A concrete implementation of the WorksheetAccesssInterface
class WorksheetAccessInterfaceImpl : public Cantor::WorksheetAccessInterface
......@@ -92,27 +90,12 @@ class WorksheetAccessInterfaceImpl : public Cantor::WorksheetAccessInterface
Worksheet* m_worksheet;
};
CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantList & args ): KParts::ReadWritePart(parent),
m_searchBar(nullptr),
m_initProgressDlg(nullptr),
m_showProgressDlg(true),
m_currectZoomAction(nullptr),
m_statusBarBlocked(false),
m_sessionStatusCounter(0)
CantorPart::CantorPart(QWidget* parentWidget, QObject* parent, const QVariantList& args ): KParts::ReadWritePart(parent)
{
QString backendName;
if(!args.isEmpty())
backendName = args.first().toString();
for (const QVariant& arg : args)
{
if (arg.toString() == QLatin1String("--noprogress") )
{
qWarning()<<"not showing the progress bar by request";
m_showProgressDlg=false;
}
}
Cantor::Backend* b = nullptr;
if (!backendName.isEmpty())
{
......@@ -623,7 +606,7 @@ void CantorPart::restartBackend()
void CantorPart::worksheetStatusChanged(Cantor::Session::Status status)
{
qDebug()<<"wsStatusChange"<<status;
qDebug()<<"worksheet status changed:" << status;
unsigned int count = ++m_sessionStatusCounter;
switch (status) {
case Cantor::Session::Running:
......@@ -688,7 +671,8 @@ void CantorPart::initialized()
Cantor::Assistant* assistant = dynamic_cast<Cantor::Assistant*>(client);
if (assistant)
{
factory()->removeClient(client);
if (factory())
factory()->removeClient(client);
removeChildClient(client);
assistant->deleteLater();
}
......
......@@ -15,14 +15,12 @@
class QWidget;
class Worksheet;
class WorksheetView;
class SarchBar;
class SearchBar;
class ScriptEditorWidget;
class KAboutData;
class QAction;
class KToggleAction;
class KSelectAction;
class QProgressDialog;
namespace Cantor{
class PanelPluginHandler;
......@@ -42,7 +40,7 @@ public:
/**
* Default constructor
*/
CantorPart(QWidget *parentWidget,QObject *parent, const QVariantList &args);
CantorPart(QWidget* , QObject*, const QVariantList& args);
/**
* Destructor
......@@ -54,12 +52,12 @@ public:
* A shell will use this to inform this Part if it should act
* read-only
*/
void setReadWrite(bool rw) override;
void setReadWrite(bool) override;
/**
* Reimplemented to disable and enable Save action
*/
void setModified(bool modified) override;
void setModified(bool) override;
KAboutData& createAboutData();
......@@ -67,11 +65,11 @@ public:
Q_SIGNALS:
void setCaption(const QString& caption, const QIcon& icon);
void showHelp(const QString& help);
void showHelp(const QString&);
void hierarchyChanged(QStringList, QStringList, QList<int>);
void hierarhyEntryNameChange(QString name, QString searchName, int depth);
void worksheetSave(const QUrl& url);
void setBackendName(const QString& name);
void worksheetSave(const QUrl&);
void setBackendName(const QString&);
void requestScrollToHierarchyEntry(QString);
void settingsChanges();
void requestDocumentation(const QString& keyword);
......@@ -94,8 +92,7 @@ protected:
* Called when this part becomes the active one,
* or if it looses activity
**/
void guiActivateEvent( KParts::GUIActivateEvent * event ) override;
void guiActivateEvent(KParts::GUIActivateEvent*) override;
void loadAssistants();
void adjustGuiToSession();
......@@ -108,27 +105,27 @@ protected Q_SLOTS:
void exportToLatex();
void evaluateOrInterrupt();
void restartBackend();
void zoomValueEdited(const QString& text);
void updateZoomWidgetValue(double zoom);
void enableTypesetting(bool enable);
void zoomValueEdited(const QString&);
void updateZoomWidgetValue(double);
void enableTypesetting(bool);
void showBackendHelp();
void print();
void printPreview();
void worksheetStatusChanged(Cantor::Session::Status stauts);
void showSessionError(const QString& error);
void worksheetStatusChanged(Cantor::Session::Status);
void showSessionError(const QString&);
void worksheetSessionLoginStarted();
void worksheetSessionLoginDone();
void initialized();
void runCommand(const QString& value);
void runCommand(const QString&);
void runAssistant();
void publishWorksheet();
void showScriptEditor(bool show);
void showScriptEditor(bool);
void scriptEditorClosed();
void runScript(const QString& file);
void runScript(const QString&);
void showSearchBar();
void showExtendedSearchBar();
......@@ -139,11 +136,11 @@ protected Q_SLOTS:
/** sets the status message, or cached it, if the StatusBar is blocked.
* Use this method instead of "emit setStatusBarText"
*/
void setStatusMessage(const QString& message);
void setStatusMessage(const QString&);
/** Shows an important status message. It makes sure the message is displayed,
* by blocking the statusbarText for 3 seconds
*/
void showImportantStatusMessage(const QString& message);
void showImportantStatusMessage(const QString&);
/** Blocks the StatusBar for new messages, so the currently shown one won't be overridden
*/
void blockStatusBar();
......@@ -153,20 +150,18 @@ protected Q_SLOTS:
void unblockStatusBar();
private:
Worksheet *m_worksheet;
WorksheetView *m_worksheetview;
SearchBar *m_searchBar;
Worksheet* m_worksheet{nullptr};
WorksheetView* m_worksheetview{nullptr};
SearchBar* m_searchBar{nullptr};
QPointer<ScriptEditorWidget> m_scriptEditor;
QProgressDialog* m_initProgressDlg;
bool m_showProgressDlg;
QAction * m_evaluate;
QAction * m_restart;
QAction* m_evaluate;
QAction* m_restart;
KSelectAction* m_zoom;
QAction* m_currectZoomAction;
QAction * m_save;
QAction * m_findNext;
QAction * m_findPrev;
QAction* m_currectZoomAction{nullptr};
QAction* m_save;