Add parameter errors in Python console.
Add tests and update existing test.
// shared pointers
%shared_ptr(ParametersAPI_Parameter)
+// exception handler
+%exception addParameter {
+ try {
+ $action
+ } catch (const std::string& str) {
+ PyErr_SetString(PyExc_SyntaxError, str.c_str());
+ return NULL;
+ }
+}
+
// all supported interfaces
%include "ParametersAPI_Parameter.h"
const std::wstring & theComment)
{
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ParametersAPI_Parameter::ID());
- return ParameterPtr(new ParametersAPI_Parameter(aFeature, theName, theExpression, theComment));
+ ParameterPtr aParam(new ParametersAPI_Parameter(aFeature, theName, theExpression, theComment));
+
+ if (!aParam->feature()->error().empty())
+ {
+ std::string anError("Error with parameter \"");
+ anError += theName + "\": " + aParam->feature()->error();
+ throw anError;
+ }
+ return aParam;
}
//--------------------------------------------------------------------------------------
--- /dev/null
+###
+### SHAPER component
+###
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+
+### Create Part
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+aPart1 = model.addParameter(Part_1_doc, "Doing", "123", "Longueur de la pièce")
+try:
+ aPart2 = model.addParameter(Part_1_doc, "Doing", "323", "Long")
+except SyntaxError as anError:
+ assert(anError != "")
+ assert(str(anError).find("Variable name is not unique.") != -1)
+
+model.end()
model.begin()
partSet = model.moduleDocument()
# check error on empty name
-Param1 = model.addParameter(partSet, "", "100")
-assert(Param1.feature().error() != "")
+try:
+ Param1 = model.addParameter(partSet, "", "100")
+except SyntaxError as anError:
+ assert(str(anError).find("Attribute \"variable\" value is empty.") != -1)
# check error on empty value
-Param2 = model.addParameter(partSet, "L", "")
-assert(Param2.feature().error() != "")
+try:
+ Param2 = model.addParameter(partSet, "L", "")
+except SyntaxError as anError:
+ assert(str(anError).find("Expression is empty.") != -1)
# check error if name is not variable
-Param3 = model.addParameter(partSet, "100", "100")
-assert(Param3.feature().error() != "")
+try:
+ Param3 = model.addParameter(partSet, "100", "100")
+except SyntaxError as anError:
+ assert(str(anError).find("Incorrect variable name.") != -1)
# check error on wrong value expression
-Param4 = model.addParameter(partSet, "N", "+-.so&@")
-assert(Param4.feature().error() != "")
+try:
+ Param4 = model.addParameter(partSet, "N", "+-.so&@")
+except SyntaxError as anError:
+ assert(str(anError).find("invalid syntax") != -1)
model.end()
aFile.close()
aListOfParameters = model.importParameters(Part_1_doc, nameFile)
+
Box_1 = model.addBox(Part_1_doc, "Longueur", "Largeur", "Hauteur")
assert(len(Box_1.feature().error()) == 0)
assert(len(aListOfParameters) > 0)
-assert(len(aListOfParameters) == 8)
+assert(len(aListOfParameters) == 5)
aComment = aLine
if(len(aName) > 0):
- aResult.append(model.addParameter(theDocument, aName, aParameter.strip(), aComment.strip()))
+ try:
+ aResult.append(model.addParameter(theDocument, aName, aParameter.strip(), aComment.strip()))
+ except SyntaxError as anError:
+ anError
aFile.close()
return aResult