Sfoglia il codice sorgente

Merge pull request #593 from jcfr/improve-ctkAbstractPythonManagerTest

Improve ctkAbstractPythonManagerTest
Jean-Christophe Fillion-Robin 9 anni fa
parent
commit
557c44e8df

+ 23 - 1
Libs/Scripting/Python/Core/Testing/Cpp/ctkAbstractPythonManagerTest.cpp

@@ -112,7 +112,7 @@ void ctkAbstractPythonManagerTester::testPythonErrorOccured_data()
 
   QTest::newRow("0") << QString("2 + 2") << false;
 
-  QTest::newRow("1") << QString("raise Exception('This is exception is expected')") << true;
+  QTest::newRow("1") << QString("raise Exception('This exception is expected')") << true;
 }
 
 // ----------------------------------------------------------------------------
@@ -131,6 +131,7 @@ void ctkAbstractPythonManagerTester::testExecuteString()
 {
   QFETCH(QString, stringToExecute);
   QFETCH(int, executeStringMode);
+  QFETCH(bool, errorOccured);
   QFETCH(QVariant, expectedReturnValue);
   QFETCH(QString, expectedVariableName);
   QFETCH(QVariant, expectedVariableValue);
@@ -139,6 +140,11 @@ void ctkAbstractPythonManagerTester::testExecuteString()
         stringToExecute,
         static_cast<ctkAbstractPythonManager::ExecuteStringMode>(executeStringMode));
 
+  QCOMPARE(this->PythonManager.pythonErrorOccured(), errorOccured);
+  if (errorOccured)
+    {
+    return;
+    }
   QCOMPARE(returnValue, expectedReturnValue);
   QCOMPARE(this->PythonManager.getVariable(expectedVariableName), expectedVariableValue);
 }
@@ -148,25 +154,41 @@ void ctkAbstractPythonManagerTester::testExecuteString_data()
 {
   QTest::addColumn<QString>("stringToExecute");
   QTest::addColumn<int>("executeStringMode");
+  QTest::addColumn<bool>("errorOccured");
   QTest::addColumn<QVariant>("expectedReturnValue");
   QTest::addColumn<QString>("expectedVariableName");
   QTest::addColumn<QVariant>("expectedVariableValue");
 
   QTest::newRow("0") << QString("a = 6542")
                      << static_cast<int>(ctkAbstractPythonManager::FileInput)
+                     << false
                      << QVariant() << QString("a") << QVariant(6542);
 
   QTest::newRow("1") << QString("6543")
                      << static_cast<int>(ctkAbstractPythonManager::FileInput)
+                     << false
                      << QVariant() << QString("a") << QVariant(6542);
 
   QTest::newRow("2") << QString("b = 6544")
                      << static_cast<int>(ctkAbstractPythonManager::EvalInput)
+                     << true
                      << QVariant() << QString("b") << QVariant();
 
   QTest::newRow("3") << QString("7")
                      << static_cast<int>(ctkAbstractPythonManager::EvalInput)
+                     << false
                      << QVariant(7) << QString("b") << QVariant();
+
+  QTest::newRow("4") << QString("sys.getrecursionlimit()")
+                     << static_cast<int>(ctkAbstractPythonManager::FileInput)
+                     << false
+                     << QVariant() << QString() << QVariant();
+
+  // This assume the default 'recursionlimit' has not been changed
+  QTest::newRow("5") << QString("sys.getrecursionlimit()")
+                     << static_cast<int>(ctkAbstractPythonManager::EvalInput)
+                     << false
+                     << QVariant(1000) << QString() << QVariant();
 }
 
 // ----------------------------------------------------------------------------