Changeset View
Changeset View
Standalone View
Standalone View
src/backends/python3/testpython3.cpp
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "testpython3.h" | 21 | #include "testpython3.h" | ||
22 | 22 | | |||
23 | #include "session.h" | 23 | #include "session.h" | ||
24 | #include "backend.h" | 24 | #include "backend.h" | ||
25 | #include "expression.h" | 25 | #include "expression.h" | ||
26 | #include "imageresult.h" | 26 | #include "imageresult.h" | ||
27 | #include "defaultvariablemodel.h" | ||||
27 | 28 | | |||
28 | QString TestPython3::backendName() | 29 | QString TestPython3::backendName() | ||
29 | { | 30 | { | ||
30 | return QLatin1String("python3"); | 31 | return QLatin1String("python3"); | ||
31 | } | 32 | } | ||
32 | 33 | | |||
33 | void TestPython3::testImportNumpy() | 34 | void TestPython3::testImportNumpy() | ||
34 | { | 35 | { | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 77 | { | |||
107 | QVERIFY(e != nullptr); | 108 | QVERIFY(e != nullptr); | ||
108 | QVERIFY(e->errorMessage().isEmpty() == true); | 109 | QVERIFY(e->errorMessage().isEmpty() == true); | ||
109 | QVERIFY(model->rowCount() == 2); //still only two variables | 110 | QVERIFY(model->rowCount() == 2); //still only two variables | ||
110 | 111 | | |||
111 | //there must be one single image result | 112 | //there must be one single image result | ||
112 | QVERIFY(e->results().size() == 1); | 113 | QVERIFY(e->results().size() == 1); | ||
113 | const Cantor::ImageResult* result = dynamic_cast<const Cantor::ImageResult*>(e->result()); | 114 | const Cantor::ImageResult* result = dynamic_cast<const Cantor::ImageResult*>(e->result()); | ||
114 | QVERIFY(result != nullptr); | 115 | QVERIFY(result != nullptr); | ||
116 | | ||||
117 | evalExp(QLatin1String("del t; del s")); | ||||
118 | } | ||||
119 | | ||||
120 | void TestPython3::testVariablesCreatingFromCode() | ||||
121 | { | ||||
122 | QAbstractItemModel* model = session()->variableModel(); | ||||
123 | QVERIFY(model != nullptr); | ||||
124 | | ||||
125 | Cantor::Expression* e=evalExp(QLatin1String("a = 15; b = 'S';")); | ||||
126 | QVERIFY(e!=nullptr); | ||||
127 | | ||||
128 | if(session()->status()==Cantor::Session::Running) | ||||
129 | waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); | ||||
130 | | ||||
131 | QCOMPARE(2, model->rowCount()); | ||||
132 | | ||||
133 | QCOMPARE(model->index(0,0).data().toString(), QLatin1String("a")); | ||||
134 | QCOMPARE(model->index(0,1).data().toString(), QLatin1String("15")); | ||||
135 | | ||||
136 | QCOMPARE(model->index(1,0).data().toString(), QLatin1String("b")); | ||||
137 | QCOMPARE(model->index(1,1).data().toString(), QLatin1String("'S'")); | ||||
138 | | ||||
139 | evalExp(QLatin1String("del a; del b")); | ||||
140 | } | ||||
141 | | ||||
142 | void TestPython3::testVariableCleanupAfterRestart() | ||||
143 | { | ||||
144 | Cantor::DefaultVariableModel* model = static_cast<Cantor::DefaultVariableModel*>(session()->variableModel()); | ||||
145 | QVERIFY(model != nullptr); | ||||
146 | | ||||
147 | Cantor::Expression* e=evalExp(QLatin1String("a = 15; b = 'S';")); | ||||
148 | QVERIFY(e!=nullptr); | ||||
149 | | ||||
150 | if(session()->status()==Cantor::Session::Running) | ||||
151 | waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); | ||||
152 | | ||||
153 | QCOMPARE(2, static_cast<QAbstractItemModel*>(model)->rowCount()); | ||||
154 | | ||||
155 | session()->logout(); | ||||
156 | session()->login(); | ||||
157 | | ||||
158 | QCOMPARE(0, static_cast<QAbstractItemModel*>(model)->rowCount()); | ||||
159 | } | ||||
160 | | ||||
161 | void TestPython3::testDictVariable() | ||||
162 | { | ||||
163 | Cantor::DefaultVariableModel* model = static_cast<Cantor::DefaultVariableModel*>(session()->variableModel()); | ||||
164 | QVERIFY(model != nullptr); | ||||
165 | | ||||
166 | Cantor::Expression* e=evalExp(QLatin1String("d = {'value': 33}")); | ||||
167 | | ||||
168 | QVERIFY(e!=nullptr); | ||||
169 | | ||||
170 | if(session()->status()==Cantor::Session::Running) | ||||
171 | waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); | ||||
172 | | ||||
173 | QCOMPARE(1, static_cast<QAbstractItemModel*>(model)->rowCount()); | ||||
174 | QCOMPARE(model->index(0,0).data().toString(), QLatin1String("d")); | ||||
175 | QCOMPARE(model->index(0,1).data().toString(), QLatin1String("{'value': 33}")); | ||||
176 | | ||||
177 | evalExp(QLatin1String("del d")); | ||||
115 | } | 178 | } | ||
116 | 179 | | |||
117 | QTEST_MAIN(TestPython3) | 180 | QTEST_MAIN(TestPython3) | ||
118 | 181 | |