From: Alexey Kondratyev Date: Fri, 15 Oct 2021 08:06:06 +0000 (+0300) Subject: [bos #26444] [EDF] (2021) SHAPER: Improve treatment of parameters X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=76bebb76786d3e283dfffb0f6555b4d0785723ce;p=modules%2Fshaper.git [bos #26444] [EDF] (2021) SHAPER: Improve treatment of parameters Update tests for importing parameters. --- diff --git a/src/ParametersPlugin/Test/TestImportInvalidParameters.py b/src/ParametersPlugin/Test/TestImportInvalidParameters.py new file mode 100644 index 000000000..1eac0e9f7 --- /dev/null +++ b/src/ParametersPlugin/Test/TestImportInvalidParameters.py @@ -0,0 +1,45 @@ +# Copyright (C) 2014-2021 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model +import os, sys + +from PyQt5.Qt import QApplication + +import salome +salome.salome_init_without_session() +salome.salome_init(1) +if QApplication.instance() is None: + app = QApplication([]) + +data_dir = os.path.join(os.path.dirname(inspect.getfile(lambda: None)), "data") + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +nameFile = "invalid_parameters.txt" + +aDir = os.path.join(data_dir, nameFile) + +aListOfParameters = model.importParameters(Part_1_doc, aDir) + +assert(len(aListOfParameters) == 0) +assert(model.checkPythonDump()) diff --git a/src/ParametersPlugin/Test/TestImportParameters.py b/src/ParametersPlugin/Test/TestImportParameters.py index 25750d0f3..a09a45202 100644 --- a/src/ParametersPlugin/Test/TestImportParameters.py +++ b/src/ParametersPlugin/Test/TestImportParameters.py @@ -44,6 +44,5 @@ aListOfParameters = model.importParameters(Part_1_doc, aDir) Box_1 = model.addBox(Part_1_doc, "Longueur", "Largeur", "Hauteur") assert(len(Box_1.feature().error()) == 0) -assert(len(aListOfParameters) > 0) assert(len(aListOfParameters) == 5) assert(model.checkPythonDump()) diff --git a/src/ParametersPlugin/data/invalid_parameters.txt b/src/ParametersPlugin/data/invalid_parameters.txt new file mode 100644 index 000000000..c119a86f8 --- /dev/null +++ b/src/ParametersPlugin/data/invalid_parameters.txt @@ -0,0 +1,5 @@ +Hauteur Longueur*Largeur + +Largeur3 #Comment +# Comment + # Comm diff --git a/src/ParametersPlugin/data/parameters.txt b/src/ParametersPlugin/data/parameters.txt index f0538715f..ca3185fdb 100644 --- a/src/ParametersPlugin/data/parameters.txt +++ b/src/ParametersPlugin/data/parameters.txt @@ -1,11 +1,5 @@ Longueur 36. # "Longueur de la pièce" Largeur 24. # Largeur de la pièce Hauteur Longueur*Largeur - -Largeur2 -Largeur3 #Comment A12 5. * 5. -# Comment -Name#Comment - # Comm Longueur2 36. #\"Comment\" #Comm #Comm \ No newline at end of file diff --git a/src/ParametersPlugin/tests.set b/src/ParametersPlugin/tests.set index 48514ff6b..668f4668f 100644 --- a/src/ParametersPlugin/tests.set +++ b/src/ParametersPlugin/tests.set @@ -28,4 +28,6 @@ SET(TEST_NAMES Test2392.py Test2474.py Test19036.py + TestImportParameters.py + TestImportInvalidParameters.py ) diff --git a/src/PythonAPI/model/parameter/import_parameter.py b/src/PythonAPI/model/parameter/import_parameter.py index 0c3bb31bd..3ff86bf8d 100644 --- a/src/PythonAPI/model/parameter/import_parameter.py +++ b/src/PythonAPI/model/parameter/import_parameter.py @@ -58,7 +58,7 @@ def importParameters(theDocument, theFileName): try: aResult.append(model.addParameter(theDocument, aName, aParameter.strip(), aComment.strip())) except SyntaxError as anError: - print(anError) + print(anError, file = sys.stderr) aFile.close() return aResult