Commit 5a1e6ce4 authored by Nikita Sirgienko's avatar Nikita Sirgienko
Browse files

[T12843][GSoC 2020] Add tests for T12843

parent 385affeb
......@@ -1511,3 +1511,13 @@ void CommandEntry::addToExecution()
connect(m_commandItem, &WorksheetTextItem::receivedFocus, worksheet(), &Worksheet::highlightItem);
worksheet()->highlightItem(m_commandItem);
}
bool CommandEntry::isExcludedFromExecution()
{
return m_isExecutionEnabled == false;
}
bool CommandEntry::isResultCollapsed()
{
return m_resultsCollapsed;
}
......@@ -61,6 +61,8 @@ class CommandEntry : public WorksheetEntry
QString currentLine();
bool isEmpty() override;
bool isExcludedFromExecution();
bool isResultCollapsed();
void setContent(const QString& content) override;
void setContent(const QDomElement& content, const KZip& file) override;
......
......@@ -47,6 +47,9 @@ configure_file("data/TestEntryLoad2.ipynb" data COPYONLY)
configure_file("data/TestResultsLoad.ipynb" data COPYONLY)
configure_file("data/TestNotebookWithJson.ipynb" data COPYONLY)
configure_file("data/TestNotebookWithModJson.ipynb" data COPYONLY)
configure_file("data/EmptyPythonWorksheet.cws" data COPYONLY)
configure_file("data/TestCommandEntryExecutionAction.cws" data COPYONLY)
configure_file("data/TwoCommandEntryWithResults.cws" data COPYONLY)
set(PATH_TO_TEST_NOTEBOOKS ${CMAKE_CURRENT_BINARY_DIR}/data)
configure_file (config-cantor-test.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-cantor-test.h )
......
......@@ -23,6 +23,7 @@
#include <KLocalizedString>
#include <QMovie>
#include <KZip>
#include <KActionCollection>
#include "worksheet_test.h"
#include "../worksheet.h"
......@@ -59,8 +60,10 @@ void WorksheetTest::initTestCase()
Worksheet* WorksheetTest::loadWorksheet(const QString& name)
{
Worksheet* w = new Worksheet(Cantor::Backend::getBackend(QLatin1String("maxima")), nullptr, false);
WorksheetView v(w, nullptr);
new WorksheetView(w, nullptr);
w->load(dataPath + name);
KActionCollection* collection = new KActionCollection(nullptr, QString());
w->createActions(collection);
return w;
}
......@@ -228,11 +231,24 @@ void WorksheetTest::testHtmlResult(WorksheetEntry* entry, int index, const QStri
QCOMPARE(result->plain(), plain);
}
void WorksheetTest::waitForSignal(QObject* sender, const char* signal)
{
QTimer timeout( this );
timeout.setSingleShot( true );
QEventLoop loop;
connect( sender, signal, &loop, SLOT(quit()) );
connect(&timeout, &QTimer::timeout, &loop, &QEventLoop::quit);
timeout.start( 25000 );
loop.exec();
}
void WorksheetTest::testJupyter1()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("Lecture-2B-Single-Atom-Lasing.ipynb")));
......@@ -817,7 +833,7 @@ void WorksheetTest::testJupyter2()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("AEC.04 - Evolutionary Strategies and Covariance Matrix Adaptation.ipynb")));
......@@ -1994,7 +2010,7 @@ void WorksheetTest::testJupyter3()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("Population_Genetics.ipynb")));
......@@ -3638,7 +3654,7 @@ void WorksheetTest::testJupyter4()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("A Reaction-Diffusion Equation Solver in Python with Numpy.ipynb")));
......@@ -4202,7 +4218,7 @@ void WorksheetTest::testJupyter5()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("Automata and Computability using Jupyter.ipynb")));
......@@ -5080,7 +5096,7 @@ void WorksheetTest::testJupyter6()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("Cue Combination with Neural Populations .ipynb")));
......@@ -5545,7 +5561,7 @@ void WorksheetTest::testJupyter7()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("Transformation2D.ipynb")));
......@@ -6513,7 +6529,7 @@ void WorksheetTest::testMarkdownAttachment()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("TestMarkdownAttachment.ipynb")));
......@@ -6563,7 +6579,7 @@ void WorksheetTest::testEntryLoad1()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("TestEntryLoad1.ipynb")));
......@@ -6599,7 +6615,7 @@ void WorksheetTest::testEntryLoad2()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("TestEntryLoad2.ipynb")));
......@@ -6695,7 +6711,7 @@ void WorksheetTest::testMimeResult()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("TestNotebookWithJson.ipynb")));
......@@ -6775,7 +6791,7 @@ void WorksheetTest::testMimeResultWithPlain()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(loadWorksheet(QLatin1String("TestNotebookWithModJson.ipynb")));
......@@ -6853,11 +6869,138 @@ void WorksheetTest::testMimeResultWithPlain()
QCOMPARE(entry, nullptr);
}
void WorksheetTest::testCommandEntryExecutionAction1()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(std::move(loadWorksheet(QLatin1String("EmptyPythonWorksheet.cws"))));
QCOMPARE(w->session()->backend()->id(), QLatin1String("python"));
CommandEntry* entry = static_cast<CommandEntry*>(WorksheetEntry::create(CommandEntry::Type, w.data()));
entry->setContent(QLatin1String("2+2"));
entry->evaluate();
waitForSignal(entry->expression(), SIGNAL(gotResult()));
QCOMPARE(entry->isExcludedFromExecution(), false);
testCommandEntry(entry, 0, 1, QLatin1String("2+2"));
testTextResult(entry, 0, QLatin1String("4"));
entry->setContent(QLatin1String("8**2"));
entry->excludeFromExecution();
entry->evaluate();
testCommandEntry(entry, 0, 1, QLatin1String("8**2"));
testTextResult(entry, 0, QLatin1String("4"));
QCOMPARE(entry->isExcludedFromExecution(), true);
entry->addToExecution();
entry->evaluate();
waitForSignal(entry->expression(), SIGNAL(gotResult()));
testCommandEntry(entry, 1, 1, QLatin1String("8**2"));
testTextResult(entry, 0, QLatin1String("64"));
QCOMPARE(entry->isExcludedFromExecution(), false);
}
void WorksheetTest::testCommandEntryExecutionAction2()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(std::move(loadWorksheet(QLatin1String("TestCommandEntryExecutionAction.cws"))));
QCOMPARE(w->session()->backend()->id(), QLatin1String("python"));
testCommandEntry(w->firstEntry(), -1, 1, QLatin1String("2+2"));
testTextResult(w->firstEntry(), 0, QLatin1String("4"));
CommandEntry* entry = static_cast<CommandEntry*>(w->firstEntry());
QCOMPARE(entry->isExcludedFromExecution(), true);
}
void WorksheetTest::testCollapsingAllResultsAction()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(std::move(loadWorksheet(QLatin1String("TwoCommandEntryWithResults.cws"))));
QCOMPARE(w->session()->backend()->id(), QLatin1String("python"));
WorksheetEntry* entry = w->firstEntry();
testCommandEntry(entry, -1, 1, QLatin1String("2**2"));
testTextResult(entry, 0, QLatin1String("4"));
entry = entry->next();
testCommandEntry(entry, -1, 1, QLatin1String("2**3"));
testTextResult(entry, 0, QLatin1String("8"));
entry = entry->next();
QCOMPARE(entry, nullptr);
w->collapseAllResults();
CommandEntry* comEntry = static_cast<CommandEntry*>(w->firstEntry());
QCOMPARE(comEntry->isResultCollapsed(), true);
comEntry = static_cast<CommandEntry*>(comEntry->next());
QCOMPARE(comEntry->isResultCollapsed(), true);
comEntry = static_cast<CommandEntry*>(comEntry->next());
QCOMPARE(entry, nullptr);
w->uncollapseAllResults();
comEntry = static_cast<CommandEntry*>(w->firstEntry());
QCOMPARE(comEntry->isResultCollapsed(), false);
comEntry = static_cast<CommandEntry*>(comEntry->next());
QCOMPARE(comEntry->isResultCollapsed(), false);
comEntry = static_cast<CommandEntry*>(comEntry->next());
QCOMPARE(entry, nullptr);
}
void WorksheetTest::testRemovingAllResultsAction()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python backend don't available", SkipSingle);
QScopedPointer<Worksheet> w(std::move(loadWorksheet(QLatin1String("TwoCommandEntryWithResults.cws"))));
QCOMPARE(w->session()->backend()->id(), QLatin1String("python"));
WorksheetEntry* entry = w->firstEntry();
testCommandEntry(entry, -1, 1, QLatin1String("2**2"));
testTextResult(entry, 0, QLatin1String("4"));
entry = entry->next();
testCommandEntry(entry, -1, 1, QLatin1String("2**3"));
testTextResult(entry, 0, QLatin1String("8"));
entry = entry->next();
QCOMPARE(entry, nullptr);
w->removeAllResults();
entry = w->firstEntry();
testCommandEntry(entry, -1, 0, QLatin1String("2**2"));
entry = entry->next();
testCommandEntry(entry, -1, 0, QLatin1String("2**3"));
entry = entry->next();
QCOMPARE(entry, nullptr);
}
void WorksheetTest::testMathRender()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
Worksheet* w = new Worksheet(Cantor::Backend::getBackend(QLatin1String("python")), nullptr);
WorksheetView v(w, nullptr);
......@@ -6890,7 +7033,7 @@ void WorksheetTest::testMathRender2()
{
Cantor::Backend* backend = Cantor::Backend::getBackend(QLatin1String("python"));
if (backend && backend->isEnabled() == false)
QSKIP("Skip, because python3 backend don't available", SkipSingle);
QSKIP("Skip, because python backend don't available", SkipSingle);
Worksheet* w = new Worksheet(Cantor::Backend::getBackend(QLatin1String("python")), nullptr);
WorksheetView v(w, nullptr);
......
......@@ -48,11 +48,17 @@ class WorksheetTest: public QObject
void testMimeResult();
void testMimeResultWithPlain();
void testCommandEntryExecutionAction1();
void testCommandEntryExecutionAction2();
void testCollapsingAllResultsAction();
void testRemovingAllResultsAction();
/* common features tests */
void testMathRender();
void testMathRender2();
private:
void waitForSignal( QObject* sender, const char* signal);
static Worksheet* loadWorksheet(const QString& name);
static int entriesCount(Worksheet* worksheet);
static Cantor::Expression* expression(WorksheetEntry* entry);
......
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