|
@@ -54,7 +54,8 @@ private Q_SLOTS:
|
|
|
void testExecuteFile();
|
|
|
void testExecuteFile_data();
|
|
|
|
|
|
- //void testPythonAttributes(); // TODO
|
|
|
+ void testPythonAttributes();
|
|
|
+ void testPythonAttributes_data();
|
|
|
|
|
|
void testPythonModule();
|
|
|
void testPythonModule_data();
|
|
@@ -271,6 +272,53 @@ void ctkAbstractPythonManagerTester::testExecuteFile_data()
|
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
+void ctkAbstractPythonManagerTester::testPythonAttributes()
|
|
|
+{
|
|
|
+ QFETCH(QString, pythonVariableName);
|
|
|
+ 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("/"),
|
|
|
+ "/PythonAttributes-test.py");
|
|
|
+ this->PythonManager.executeFile(test_path);
|
|
|
+
|
|
|
+ QStringList AttributeList = this->PythonManager.pythonAttributes(pythonVariableName, QString("__main__").toLatin1(), false);
|
|
|
+
|
|
|
+ foreach (const QString& expectedAttribute, expectedAttributeList)
|
|
|
+ {
|
|
|
+ QVERIFY(AttributeList.contains(expectedAttribute));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
+void ctkAbstractPythonManagerTester::testPythonAttributes_data()
|
|
|
+{
|
|
|
+ QTest::addColumn<QString>("pythonVariableName");
|
|
|
+ QTest::addColumn<QStringList>("expectedAttributeList");
|
|
|
+
|
|
|
+ QTest::newRow("d.foo_class()")
|
|
|
+ << "d.foo_class()"
|
|
|
+ << (QStringList()
|
|
|
+ << "FOO_CLASS_MEMBER"
|
|
|
+ << "foo_class_method"
|
|
|
+ << "foo_instance_member"
|
|
|
+ << "foo_instance_method"
|
|
|
+ << "instantiate_bar");
|
|
|
+
|
|
|
+ QTest::newRow("d.foo_class().instantiate_bar()")
|
|
|
+ << "d.foo_class().instantiate_bar()"
|
|
|
+ << (QStringList()
|
|
|
+ << "BAR_CLASS_MEMBER"
|
|
|
+ << "bar_class_method"
|
|
|
+ << "bar_instance_member"
|
|
|
+ << "bar_instance_method");
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
void ctkAbstractPythonManagerTester::testPythonModule()
|
|
|
{
|
|
|
QFETCH(QString, pythonCode);
|