Salome HOME
Adjust test cases according to updated Arc behavior
[modules/shaper.git] / src / PythonAPI / model / tests / tests.py
index 88e0731d4cf2c86e3cc1e3c4257d9ad774c0b70d..2cc13febd619db92e70a9ada4c5fa50429de9116 100644 (file)
@@ -1,7 +1,11 @@
 from GeomAlgoAPI import *
 from GeomAPI import *
+from GeomDataAPI import *
+from ModelAPI import ModelAPI_Feature
 import math
+from salome.shaper.model import sketcher
 
+TOLERANCE = 1.e-7
 
 aShapeTypes = {
   GeomAPI_Shape.SOLID:  "GeomAPI_Shape.SOLID",
@@ -139,3 +143,28 @@ def testHaveNamingFaces(theFeature, theModel, thePartDoc) :
     name = attrSelection.namingName()
     assert(shape.isFace())
     assert(name != ""), "String empty"
+
+def testNbSubFeatures(theComposite, theKindOfSub, theExpectedCount):
+  """ Tests number of sub-features of the given type
+  :param theComposite     composite feature to check its subs
+  :param theKindOfSub     kind of sub-feature to calculate count
+  :param theExpectedCount expected number of sub-features
+  """
+  count = 0
+  for aSub in theComposite.features().list():
+    aFeature = ModelAPI_Feature.feature(aSub)
+    if aFeature is not None and aFeature.getKind() == theKindOfSub:
+       count += 1
+  assert (count == theExpectedCount), "Number of sub-features of type {}: {}, expected {}".format(theKindOfSub, count, theExpectedCount)
+
+def assertSketchArc(theArcFeature):
+  """ Tests whether the arc is correctly defined
+  """
+  aCenterPnt = geomDataAPI_Point2D(theArcFeature.attribute("center_point"))
+  aStartPnt = geomDataAPI_Point2D(theArcFeature.attribute("start_point"))
+  aEndPnt = geomDataAPI_Point2D(theArcFeature.attribute("end_point"))
+  aRadius = theArcFeature.real("radius")
+  aDistCS = sketcher.tools.distancePointPoint(aCenterPnt, aStartPnt)
+  aDistCE = sketcher.tools.distancePointPoint(aCenterPnt, aEndPnt)
+  assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
+  assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong arc: radius is {0}, expected {1}".format(aRadius.value(), aDistCS)