diff --git a/src/Mod/Test/Gui/AppTestGui.cpp b/src/Mod/Test/Gui/AppTestGui.cpp index 7c2ef2142..548e43106 100644 --- a/src/Mod/Test/Gui/AppTestGui.cpp +++ b/src/Mod/Test/Gui/AppTestGui.cpp @@ -79,41 +79,6 @@ private: return Py::None(); } }; -/* -static PyObject* addTest(PyObject *self, PyObject *args) -{ - char *pstr=0; - if (!PyArg_ParseTuple(args, "|s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception - - TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance(); - if (pstr) - dlg->addUnitTest(QString::fromLatin1(pstr)); - dlg->show(); - dlg->raise(); - Py_Return; -} - -static PyObject* setTest(PyObject *self, PyObject *args) -{ - char *pstr=0; - if (!PyArg_ParseTuple(args, "|s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception - - TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance(); - if (pstr) - dlg->setUnitTest(QString::fromLatin1(pstr)); - dlg->show(); - dlg->raise(); - Py_Return; -} -*/ -/* registration table */ -//static struct PyMethodDef TestGui_methods[] = { -// {"addTest", addTest, 1}, -// {"setTest", setTest, 1}, -// {NULL, NULL} /* end of table marker */ -//}; void loadTestResource() { @@ -130,10 +95,6 @@ void AppTestGuiExport initQtUnitGui() // with the Python runtime system (void)new UnitTestModule; - //if(PyType_Ready(&TestGui::UnitTestPy::Type) < 0) return; - //PyObject* pyModule = Py_InitModule("QtUnitGui", TestGui_methods); /* mod name, table ptr */ - //union PyType_Object pyDlgType = {&TestGui::UnitTestPy::Type}; - //PyModule_AddObject(pyModule, "UnitTest", pyDlgType.o); Base::Console().Log("Loading GUI of Test module... done\n"); // add resources and reloads the translators diff --git a/src/Mod/Test/Gui/UnitTestImp.cpp b/src/Mod/Test/Gui/UnitTestImp.cpp index 331f9d74f..5ecf4d52c 100644 --- a/src/Mod/Test/Gui/UnitTestImp.cpp +++ b/src/Mod/Test/Gui/UnitTestImp.cpp @@ -244,6 +244,14 @@ void UnitTestDialog::setUnitTest(const QString& unit) } } +/** + * Clears the unit tests. + */ +void UnitTestDialog::clearUnitTests() +{ + this->comboTests->clear(); +} + /** * Returns the unit test. */ diff --git a/src/Mod/Test/Gui/UnitTestImp.h b/src/Mod/Test/Gui/UnitTestImp.h index ec8556bc0..ad7e6daef 100644 --- a/src/Mod/Test/Gui/UnitTestImp.h +++ b/src/Mod/Test/Gui/UnitTestImp.h @@ -38,6 +38,7 @@ public: void showErrorDialog(const char* title, const char* message); void addUnitTest(const QString& unit); void setUnitTest(const QString& unit); + void clearUnitTests(); QString getUnitTest() const; void setStatusText(const QString& text); void setProgressFraction(float fraction, const QString& = QString::null); diff --git a/src/Mod/Test/Gui/UnitTestPy.cpp b/src/Mod/Test/Gui/UnitTestPy.cpp index 2311d0930..2a9bda1b0 100644 --- a/src/Mod/Test/Gui/UnitTestPy.cpp +++ b/src/Mod/Test/Gui/UnitTestPy.cpp @@ -55,6 +55,8 @@ void UnitTestDialogPy::init_type() add_varargs_method("setErrorCount",&UnitTestDialogPy::setErrorCount,"setErrorCount"); add_varargs_method("setRemainCount",&UnitTestDialogPy::setRemainCount,"setRemainCount"); add_varargs_method("updateGUI",&UnitTestDialogPy::updateGUI,"updateGUI"); + add_varargs_method("addUnitTest",&UnitTestDialogPy::addUnitTest,"addUnitTest"); + add_varargs_method("clearUnitTests",&UnitTestDialogPy::clearUnitTests,"clearUnitTests"); } UnitTestDialogPy::UnitTestDialogPy() @@ -191,262 +193,25 @@ Py::Object UnitTestDialogPy::updateGUI(const Py::Tuple& args) { if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); - qApp->processEvents(); + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); return Py::None(); } -//-------------------------------------------------------------------------- -// Type structure -//-------------------------------------------------------------------------- - -PyTypeObject TestGui::UnitTestPy::Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /*ob_size*/ - "TestGui.UnitTest", /*tp_name*/ - sizeof(UnitTestPy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - PyDestructor, /*tp_dealloc*/ - 0, /*tp_print*/ - __getattr, /*tp_getattr*/ - __setattr, /*tp_setattr*/ - 0, /*tp_compare*/ - __repr, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call */ - 0, /*tp_str */ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - /* --- Functions to access object as input/output buffer ---------*/ - 0, /* tp_as_buffer */ - /* --- Flags to define presence of optional/expanded features */ - Py_TPFLAGS_HAVE_CLASS, /*tp_flags */ - "About TestGui.UnitTest", /*tp_doc */ - 0, /*tp_traverse */ - 0, /*tp_clear */ - 0, /*tp_richcompare */ - 0, /*tp_weaklistoffset */ - 0, /*tp_iter */ - 0, /*tp_iternext */ - 0, /*tp_methods */ - 0, /*tp_members */ - 0, /*tp_getset */ - &Base::PyObjectBase::Type, /*tp_base */ - 0, /*tp_dict */ - 0, /*tp_descr_get */ - 0, /*tp_descr_set */ - 0, /*tp_dictoffset */ - 0, /*tp_init */ - 0, /*tp_alloc */ - UnitTestPy::PyMake, /*tp_new */ - 0, /*tp_free Low-level free-memory routine */ - 0, /*tp_is_gc For PyObject_IS_GC */ - 0, /*tp_bases */ - 0, /*tp_mro method resolution order */ - 0, /*tp_cache */ - 0, /*tp_subclasses */ - 0 /*tp_weaklist */ - -}; - -//-------------------------------------------------------------------------- -// Methods structure -//-------------------------------------------------------------------------- -PyMethodDef TestGui::UnitTestPy::Methods[] = { - PYMETHODEDEF(clearErrorList) - PYMETHODEDEF(insertError) - PYMETHODEDEF(setUnitTest) - PYMETHODEDEF(getUnitTest) - PYMETHODEDEF(setStatusText) - PYMETHODEDEF(setProgressFraction) - PYMETHODEDEF(errorDialog) - PYMETHODEDEF(setRunCount) - PYMETHODEDEF(setFailCount) - PYMETHODEDEF(setErrorCount) - PYMETHODEDEF(setRemainCount) - PYMETHODEDEF(updateGUI) - {NULL, NULL} /* Sentinel */ -}; - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -TestGui::UnitTestPy::UnitTestPy(PyTypeObject *T) -: PyObjectBase(0, T) +Py::Object UnitTestDialogPy::addUnitTest(const Py::Tuple& args) { + char *pstr; + if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) + throw Py::Exception(); + + TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance(); + dlg->addUnitTest(QString::fromLatin1(pstr)); + return Py::None(); } -PyObject *UnitTestPy::PyMake(PyTypeObject *ignored, PyObject *args, PyObject *kwds) // Python wrapper +Py::Object UnitTestDialogPy::clearUnitTests(const Py::Tuple& args) { - return new UnitTestPy(); + if (!PyArg_ParseTuple(args.ptr(), "")) + throw Py::Exception(); + UnitTestDialog::instance()->clearUnitTests(); + return Py::None(); } - -//-------------------------------------------------------------------------- -// destructor -//-------------------------------------------------------------------------- -UnitTestPy::~UnitTestPy() // Everything handled in parent -{ -} - - -//-------------------------------------------------------------------------- -// UnitTestPy representation -//-------------------------------------------------------------------------- -PyObject *UnitTestPy::_repr(void) -{ - return Py_BuildValue("s", "UnitTest"); -} - -//-------------------------------------------------------------------------- -// UnitTestPy Attributes -//-------------------------------------------------------------------------- -PyObject *UnitTestPy::_getattr(char *attr) // __getattr__ function: note only need to handle new state -{ - _getattr_up(PyObjectBase); -} - -int UnitTestPy::_setattr(char *attr, PyObject *value) // __setattr__ function: note only need to handle new state -{ - return PyObjectBase::_setattr(attr, value); -} - - -//-------------------------------------------------------------------------- -// Python wrappers -//-------------------------------------------------------------------------- - -PYFUNCIMP_D(UnitTestPy,clearErrorList) -{ - PY_TRY { - UnitTestDialog::instance()->clearErrorList(); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,insertError) -{ - char *failure=0; - char *details=0; - if (!PyArg_ParseTuple(args, "ss", &failure,&details)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->insertError(QString::fromLatin1(failure), - QString::fromLatin1(details)); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,setUnitTest) -{ - char *pstr=0; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->setUnitTest(QString::fromLatin1(pstr)); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,getUnitTest) -{ - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - return Py_BuildValue("s", (const char*)UnitTestDialog::instance()->getUnitTest().toAscii()); - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,setStatusText) -{ - char *pstr=0; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->setStatusText(QString::fromLatin1(pstr)); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,setProgressFraction) -{ - float fraction; - char* pColor=0; - if (!PyArg_ParseTuple(args, "f|s",&fraction, &pColor)) // convert args: Python->C - return NULL; // NULL triggers exception - - PY_TRY { - if (pColor) - UnitTestDialog::instance()->setProgressFraction(fraction,QString::fromLatin1(pColor)); - else - UnitTestDialog::instance()->setProgressFraction(fraction); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,errorDialog) -{ - char *title=0; - char *message=0; - if (!PyArg_ParseTuple(args, "ss", &title, &message)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->showErrorDialog(title,message); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,setRunCount) -{ - int count; - if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->setRunCount(count); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,setFailCount) -{ - int count; - if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->setFailCount(count); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,setErrorCount) -{ - int count; - if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->setErrorCount(count); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,setRemainCount) -{ - int count; - if (!PyArg_ParseTuple(args, "i", &count)) // convert args: Python->C - return NULL; // NULL triggers exception - PY_TRY { - UnitTestDialog::instance()->setRemainCount(count); - Py_Return; - }PY_CATCH; -} - -PYFUNCIMP_D(UnitTestPy,updateGUI) -{ - PY_TRY { - qApp->processEvents(); - Py_Return; - }PY_CATCH; -} - diff --git a/src/Mod/Test/Gui/UnitTestPy.h b/src/Mod/Test/Gui/UnitTestPy.h index c2a24222f..9b41112f0 100644 --- a/src/Mod/Test/Gui/UnitTestPy.h +++ b/src/Mod/Test/Gui/UnitTestPy.h @@ -56,6 +56,8 @@ public: Py::Object setErrorCount (const Py::Tuple&); Py::Object setRemainCount (const Py::Tuple&); Py::Object updateGUI (const Py::Tuple&); + Py::Object addUnitTest (const Py::Tuple&); + Py::Object clearUnitTests (const Py::Tuple&); private: typedef PyObject* (*method_varargs_handler)(PyObject *_self, PyObject *_args); @@ -63,43 +65,6 @@ private: static PyObject *method_varargs_ext_handler(PyObject *_self, PyObject *_args); }; -//=========================================================================== -// UnitTestPy - Python wrapper -//=========================================================================== - -class UnitTestPy :public Base::PyObjectBase -{ - Py_Header; - -protected: - ~UnitTestPy(); - -public: - UnitTestPy(PyTypeObject *T = &Type); - static PyObject *PyMake(PyTypeObject *, PyObject *, PyObject *); - - //--------------------------------------------------------------------- - // python exports goes here +++++++++++++++++++++++++++++++++++++++++++ - //--------------------------------------------------------------------- - - virtual PyObject *_repr(void); // the representation - PyObject *_getattr(char *attr); // __getattr__ function - int _setattr(char *attr, PyObject *value); // __setattr__ function - - PYFUNCDEF_D(UnitTestPy,clearErrorList) - PYFUNCDEF_D(UnitTestPy,insertError) - PYFUNCDEF_D(UnitTestPy,setUnitTest) - PYFUNCDEF_D(UnitTestPy,getUnitTest) - PYFUNCDEF_D(UnitTestPy,setStatusText) - PYFUNCDEF_D(UnitTestPy,setProgressFraction) - PYFUNCDEF_D(UnitTestPy,errorDialog) - PYFUNCDEF_D(UnitTestPy,setRunCount) - PYFUNCDEF_D(UnitTestPy,setFailCount) - PYFUNCDEF_D(UnitTestPy,setErrorCount) - PYFUNCDEF_D(UnitTestPy,setRemainCount) - PYFUNCDEF_D(UnitTestPy,updateGUI) -}; - } //namespace TESTGUI_UNITTESTPY_H diff --git a/src/Mod/Test/TestApp.py b/src/Mod/Test/TestApp.py index 9ee92b6b4..b57bafb4e 100644 --- a/src/Mod/Test/TestApp.py +++ b/src/Mod/Test/TestApp.py @@ -70,7 +70,8 @@ def Test(s): def testAll(): - TestText(All()) + r = unittest.TextTestRunner(stream=sys.stdout, verbosity=2) + r.run(All()) def testUnit():