App: Fix Metadata Py constructors
Also adds unit tests for the corrected Copy and Default constructors.
This commit is contained in:
@@ -48,36 +48,32 @@ std::string MetadataPy::representation(void) const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
PyObject* MetadataPy::PyMake(struct _typeobject*, PyObject* args, PyObject*) // Python wrapper
|
||||
PyObject* MetadataPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// create a new instance of MetadataPy and the Twin object
|
||||
const char* filename;
|
||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
||||
return nullptr;
|
||||
try {
|
||||
auto md = new Metadata(filename);
|
||||
return new MetadataPy(md);
|
||||
}
|
||||
catch (...) {
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "Failed to create Metadata object");
|
||||
return nullptr;
|
||||
}
|
||||
return new MetadataPy(nullptr);
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
setTwinPointer(new Metadata());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Main class constructor -- takes a file path, loads the metadata from it
|
||||
PyErr_Clear();
|
||||
const char* file;
|
||||
if (PyArg_ParseTuple(args, "s", &file)) {
|
||||
App::Metadata a(file);
|
||||
*(getMetadataPtr()) = a;
|
||||
return 0;
|
||||
const char* filename;
|
||||
if (PyArg_ParseTuple(args, "s", &filename)) {
|
||||
try {
|
||||
auto md = new Metadata(filename);
|
||||
setTwinPointer(md);
|
||||
return 0;
|
||||
}
|
||||
catch (...) {
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "Failed to create Metadata object");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
@@ -85,11 +81,11 @@ int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
PyObject* o;
|
||||
if (PyArg_ParseTuple(args, "O!", &(App::MetadataPy::Type), &o)) {
|
||||
App::Metadata* a = static_cast<App::MetadataPy*>(o)->getMetadataPtr();
|
||||
*(getMetadataPtr()) = *a;
|
||||
setTwinPointer(new Metadata(*a));
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "path to metadata file expected");
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, "metadata object or path to metadata file expected");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user