瀏覽代碼

ENH: PythonManagerTest: Add testPythonAttributeValues

Jean-Christophe Fillion-Robin 7 年之前
父節點
當前提交
8e17fbe2f0
共有 1 個文件被更改,包括 63 次插入1 次删除
  1. 63 1
      Libs/Scripting/Python/Core/Testing/Cpp/ctkAbstractPythonManagerTest.cpp

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

@@ -57,6 +57,9 @@ private Q_SLOTS:
   void testPythonAttributes();
   void testPythonAttributes_data();
 
+  void testPythonAttributeValues();
+  void testPythonAttributeValues_data();
+
   void testPythonModule();
   void testPythonModule_data();
 
@@ -278,7 +281,6 @@ void ctkAbstractPythonManagerTester::testPythonAttributes()
   QFETCH(QStringList, expectedAttributeList);
 
   QString test_path = __FILE__; // return the local path of this source file
-  // replace "ctkAbstractPythonManagerTest.py" by "PythonAttributes-test.py"
   test_path.lastIndexOf("/");
   test_path.replace(test_path.lastIndexOf("/"),
                          test_path.size() - test_path.lastIndexOf("/"),
@@ -340,6 +342,66 @@ void ctkAbstractPythonManagerTester::testPythonAttributes_data()
 }
 
 // ----------------------------------------------------------------------------
+void ctkAbstractPythonManagerTester::testPythonAttributeValues()
+{
+  QFETCH(QString, variableName);
+  QFETCH(QVariant, expectedVariableValue);
+
+  QString test_path = __FILE__; // return the local path of this source file
+  test_path.lastIndexOf("/");
+  test_path.replace(test_path.lastIndexOf("/"),
+                         test_path.size() - test_path.lastIndexOf("/"),
+                         "/PythonAttributes-test.py");
+  this->PythonManager.executeFile(test_path);
+
+  QCOMPARE(
+        expectedVariableValue,
+        this->PythonManager.getVariable(variableName));
+}
+
+// ----------------------------------------------------------------------------
+void ctkAbstractPythonManagerTester::testPythonAttributeValues_data()
+{
+  QTest::addColumn<QString>("variableName");
+  QTest::addColumn<QVariant>("expectedVariableValue");
+
+  // d.foo_class().instantiate_bar().bar_maths(5)
+  QTest::newRow("")
+      << "d.foo_class().instantiate_bar().bar_maths(5).MATHS_CLASS_MEMBER"
+      << QVariant(0.1);
+
+  QTest::newRow("")
+      << "d.foo_class().instantiate_bar().bar_maths(5).maths_instance_member"
+      << QVariant(5);
+
+  // MultipleArg( 5 + 5 , '(')
+  QTest::newRow("")
+      << "MultipleArg( 5 + 5 , '(').multipleArg_instance_member_num"
+      << QVariant(10);
+
+  QTest::newRow("")
+      << "MultipleArg( 5 + 5 , '(').multipleArg_instance_member_str"
+      << QVariant("(");
+
+  QTest::newRow("")
+      << "MultipleArg( 5 + 5 , '(').multipleArg_instance_member_other"
+      << QVariant(0);
+
+  // MultipleArg( 5 + 5 , '\"', 0.1)
+  QTest::newRow("")
+      << "MultipleArg( 5 + 5 , '\"', 0.1).multipleArg_instance_member_num"
+      << QVariant(0);
+
+  QTest::newRow("")
+      << "MultipleArg( 5 + 5 , '\"', 0.1).multipleArg_instance_member_str"
+      << QVariant('"');
+
+  QTest::newRow("")
+      << "MultipleArg( 5 + 5 , '\"', 0.1).multipleArg_instance_member_other"
+      << QVariant(0.1);
+}
+
+// ----------------------------------------------------------------------------
 void ctkAbstractPythonManagerTester::testPythonModule()
 {
   QFETCH(QString, pythonCode);