Gui: make unit tests working from command line if Gui is up
This commit is contained in:
@@ -1291,15 +1291,26 @@ void MainWindow::delayedStartup()
|
||||
{
|
||||
// automatically run unit tests in Gui
|
||||
if (App::Application::Config()["RunMode"] == "Internal") {
|
||||
try {
|
||||
Base::Interpreter().runString(Base::ScriptFactory().ProduceScript("FreeCADTest"));
|
||||
}
|
||||
catch (const Base::SystemExitException&) {
|
||||
throw;
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}
|
||||
QTimer::singleShot(1000, this, []{
|
||||
try {
|
||||
Base::Interpreter().runString(
|
||||
"import sys\n"
|
||||
"import FreeCAD\n"
|
||||
"import QtUnitGui\n\n"
|
||||
"testCase = FreeCAD.ConfigGet(\"TestCase\")\n"
|
||||
"QtUnitGui.addTest(testCase)\n"
|
||||
"QtUnitGui.setTest(testCase)\n"
|
||||
"result = QtUnitGui.runTest()\n"
|
||||
"sys.stdout.flush()\n"
|
||||
"sys.exit(0 if result else 1)");
|
||||
}
|
||||
catch (const Base::SystemExitException&) {
|
||||
throw;
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ public:
|
||||
add_varargs_method("UnitTest",&Module::new_UnitTest,"UnitTest");
|
||||
add_varargs_method("setTest",&Module::setTest,"setTest");
|
||||
add_varargs_method("addTest",&Module::addTest,"addTest");
|
||||
add_varargs_method("runTest",&Module::runTest,"runTest");
|
||||
add_varargs_method("testILoggerBlocker",&Module::testILoggerBlocker,"testILoggerBlocker");
|
||||
initialize("This module is the QtUnitGui module"); // register with Python
|
||||
}
|
||||
@@ -160,6 +161,15 @@ private:
|
||||
dlg->raise();
|
||||
return Py::None();
|
||||
}
|
||||
Py::Object runTest(const Py::Tuple& args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args.ptr(), ""))
|
||||
throw Py::Exception();
|
||||
|
||||
TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
|
||||
bool success = dlg->runCurrentTest();
|
||||
return Py::Boolean(success);
|
||||
}
|
||||
Py::Object testILoggerBlocker(const Py::Tuple& args) {
|
||||
(void) args;
|
||||
ILoggerBlockerTest iltest;
|
||||
|
||||
@@ -274,6 +274,19 @@ QString UnitTestDialog::getUnitTest() const
|
||||
return ui->comboTests->currentText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the currently selected test and closes the dialog afterwards.
|
||||
* It returns true if all tests have passed and false otherwise.
|
||||
*/
|
||||
bool UnitTestDialog::runCurrentTest()
|
||||
{
|
||||
clearErrorList();
|
||||
on_startButton_clicked();
|
||||
int count = ui->treeViewFailure->topLevelItemCount();
|
||||
reject();
|
||||
return (count == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text in the status bar.
|
||||
*/
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
void setUnitTest(const QString& unit);
|
||||
void clearUnitTests();
|
||||
QString getUnitTest() const;
|
||||
bool runCurrentTest();
|
||||
void setStatusText(const QString& text);
|
||||
void setProgressFraction(float fraction, const QString& = QString());
|
||||
void clearErrorList();
|
||||
|
||||
Reference in New Issue
Block a user