]> SALOME platform Git repositories - modules/shaper.git/blob - src/ParametersPlugin/Test/TestParameterDelete.py
Salome HOME
[Code coverage ParametersPlugin]: Unit tests for parameter remove and for error treating
[modules/shaper.git] / src / ParametersPlugin / Test / TestParameterDelete.py
1 ## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 from salome.shaper import model
22 from ModelAPI import *
23 import math
24
25 def assertLineLength(theLine, theLength):
26     dx = theLine.startPoint().x() - theLine.endPoint().x()
27     dy = theLine.startPoint().y() - theLine.endPoint().y()
28     assert(math.fabs(dx**2 + dy**2 - theLength**2)  < 1.e-8), "Line length {} is not equal to expected {}".format(math.sqrt(dx**2 + dy**2), theLength)
29
30
31 model.begin()
32 partSet = model.moduleDocument()
33 Part_1 = model.addPart(partSet)
34 Part_1_doc = Part_1.document()
35 ParamLen = model.addParameter(Part_1_doc, "Len", "100")
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
37 SketchLine_1 = Sketch_1.addLine(0, -30, 100, -30)
38 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), "Len")
39 model.do()
40
41 aLength = ParamLen.value()
42 assertLineLength(SketchLine_1, aLength)
43
44 # delete parameter
45 model.removeParameter(Part_1_doc, ParamLen)
46 model.do()
47
48 # move line and check the constraint is still here
49 SketchLine_1.startPoint().setValue(SketchLine_1.startPoint().x() + 10., SketchLine_1.startPoint().y())
50 model.do()
51 assertLineLength(SketchLine_1, aLength)
52
53 model.end()