Test: add test feature for unit tests

This commit is contained in:
wmayer
2022-08-22 15:46:40 +02:00
parent 71015d23d0
commit 8efe30c8a9
4 changed files with 101 additions and 0 deletions

View File

@@ -24,10 +24,14 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <boost/core/ignore_unused.hpp>
#include <sstream>
#endif
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Interpreter.h>
#include <Base/Unit.h>
#include <CXX/Objects.hxx>
#include "FeatureTest.h"
#include "Material.h"
@@ -235,3 +239,56 @@ DocumentObjectExecReturn *FeatureTestPlacement::execute()
MultRight.setValue(q1.multRight(p2));
return nullptr;
}
// ----------------------------------------------------------------------------
PROPERTY_SOURCE(App::FeatureTestAttribute, App::DocumentObject)
FeatureTestAttribute::FeatureTestAttribute()
{
ADD_PROPERTY(Object, (Py::Object()));
ADD_PROPERTY(Attribute, ("Name"));
}
FeatureTestAttribute::~FeatureTestAttribute()
{
Base::PyGILStateLocker lock;
try {
Object.getValue().getAttr("Name");
#if PYCXX_VERSION_MAJOR >= 7
Py::ifPyErrorThrowCxxException();
#else
if (PyErr_Occurred())
throw Py::RuntimeError();
#endif
}
catch (Py::RuntimeError& e) {
e.clear();
}
catch (Py::Exception& e) {
e.clear();
Base::Console().Error("Unexpected exception in ~FeatureTestRemoval()\n");
}
}
DocumentObjectExecReturn *FeatureTestAttribute::execute()
{
Base::PyGILStateLocker lock;
try {
Object.getValue().getAttr(Attribute.getValue());
#if PYCXX_VERSION_MAJOR >= 7
Py::ifPyErrorThrowCxxException();
#else
if (PyErr_Occurred())
throw Py::AttributeError();
#endif
}
catch (Py::AttributeError& e) {
e.clear();
std::stringstream str;
str << "No such attribute '" << Attribute.getValue() << "'";
throw Base::AttributeError(str.str());
}
return StdReturn;
}