Changeset View
Changeset View
Standalone View
Standalone View
src/backends/python2/testpython2.cpp
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "testpython2.h" | 21 | #include "testpython2.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 "result.h" | 26 | #include "result.h" | ||
27 | #include "defaultvariablemodel.h" | ||||
27 | 28 | | |||
28 | QString TestPython2::backendName() | 29 | QString TestPython2::backendName() | ||
29 | { | 30 | { | ||
30 | return QLatin1String("python2"); | 31 | return QLatin1String("python2"); | ||
31 | } | 32 | } | ||
32 | 33 | | |||
33 | void TestPython2::testImportNumpy() | 34 | void TestPython2::testImportNumpy() | ||
34 | { | 35 | { | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 72 | { | |||
76 | )); | 77 | )); | ||
77 | 78 | | |||
78 | QVERIFY( e!=nullptr ); | 79 | QVERIFY( e!=nullptr ); | ||
79 | QVERIFY( e->result()!=nullptr ); | 80 | QVERIFY( e->result()!=nullptr ); | ||
80 | 81 | | |||
81 | QString result=e->result()->toHtml(); | 82 | QString result=e->result()->toHtml(); | ||
82 | 83 | | |||
83 | QCOMPARE( cleanOutput(result ), QLatin1String("4 6") ); | 84 | QCOMPARE( cleanOutput(result ), QLatin1String("4 6") ); | ||
85 | | ||||
86 | evalExp(QLatin1String("del a; del b")); | ||||
87 | } | ||||
88 | | ||||
89 | void TestPython2::testVariablesCreatingFromCode() | ||||
90 | { | ||||
91 | QAbstractItemModel* model = session()->variableModel(); | ||||
92 | QVERIFY(model != nullptr); | ||||
93 | | ||||
94 | Cantor::Expression* e=evalExp(QLatin1String("a = 15; b = 'S';")); | ||||
95 | QVERIFY(e!=nullptr); | ||||
96 | | ||||
97 | if(session()->status()==Cantor::Session::Running) | ||||
98 | waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); | ||||
99 | | ||||
100 | QCOMPARE(2, model->rowCount()); | ||||
101 | | ||||
102 | QCOMPARE(model->index(0,0).data().toString(), QLatin1String("a")); | ||||
103 | QCOMPARE(model->index(0,1).data().toString(), QLatin1String("15")); | ||||
104 | | ||||
105 | QCOMPARE(model->index(1,0).data().toString(), QLatin1String("b")); | ||||
106 | QCOMPARE(model->index(1,1).data().toString(), QLatin1String("'S'")); | ||||
107 | | ||||
108 | evalExp(QLatin1String("del a; del b")); | ||||
109 | } | ||||
110 | | ||||
111 | void TestPython2::testVariableCleanupAfterRestart() | ||||
112 | { | ||||
113 | Cantor::DefaultVariableModel* model = session()->variableModel(); | ||||
114 | QVERIFY(model != nullptr); | ||||
115 | | ||||
116 | Cantor::Expression* e=evalExp(QLatin1String("a = 15; b = 'S';")); | ||||
117 | QVERIFY(e!=nullptr); | ||||
118 | | ||||
119 | if(session()->status()==Cantor::Session::Running) | ||||
120 | waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); | ||||
121 | | ||||
122 | QCOMPARE(2, static_cast<QAbstractItemModel*>(model)->rowCount()); | ||||
123 | | ||||
124 | session()->logout(); | ||||
125 | session()->login(); | ||||
126 | | ||||
127 | QCOMPARE(0, static_cast<QAbstractItemModel*>(model)->rowCount()); | ||||
84 | } | 128 | } | ||
85 | 129 | | |||
130 | void TestPython2::testDictVariable() | ||||
131 | { | ||||
132 | Cantor::DefaultVariableModel* model = session()->variableModel(); | ||||
133 | QVERIFY(model != nullptr); | ||||
134 | | ||||
135 | Cantor::Expression* e=evalExp(QLatin1String("d = {'value': 33}")); | ||||
136 | | ||||
137 | QVERIFY(e!=nullptr); | ||||
138 | | ||||
139 | if(session()->status()==Cantor::Session::Running) | ||||
140 | waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); | ||||
141 | | ||||
142 | QCOMPARE(1, static_cast<QAbstractItemModel*>(model)->rowCount()); | ||||
143 | QCOMPARE(model->index(0,0).data().toString(), QLatin1String("d")); | ||||
144 | QCOMPARE(model->index(0,1).data().toString(), QLatin1String("{'value': 33}")); | ||||
145 | | ||||
146 | evalExp(QLatin1String("del d")); | ||||
147 | } | ||||
148 | | ||||
149 | | ||||
86 | QTEST_MAIN(TestPython2) | 150 | QTEST_MAIN(TestPython2) | ||
87 | 151 | |