From: Renaud NEDELEC Date: Mon, 19 Oct 2015 11:37:36 +0000 (+0200) Subject: [PythonAPI] added some more unit tests X-Git-Tag: V_2.1.0~206^2~92 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Frnc%2Fsketcher_api;p=modules%2Fshaper.git [PythonAPI] added some more unit tests --- diff --git a/src/PythonAPI/CMakeLists.txt b/src/PythonAPI/CMakeLists.txt index bda9c204c..534588452 100644 --- a/src/PythonAPI/CMakeLists.txt +++ b/src/PythonAPI/CMakeLists.txt @@ -11,5 +11,7 @@ INCLUDE(UnitTest) ADD_UNIT_TESTS( TestModeler.py TestSketcherAddLine.py + TestSketcherAddCircle.py TestSketcherSetCoincident.py + TestSketcherSetParallel.py ) diff --git a/src/PythonAPI/Test/TestSketcherAddCircle.py b/src/PythonAPI/Test/TestSketcherAddCircle.py new file mode 100644 index 000000000..ac956e0db --- /dev/null +++ b/src/PythonAPI/Test/TestSketcherAddCircle.py @@ -0,0 +1,14 @@ +import unittest +import modeler +from TestSketcher import SketcherTestCase + +class SketcherAddCircle(SketcherTestCase): + def runTest(self): + circle = self.sketch.addCircle(0, 10, 20) + self.assertEqual(circle.centerData().x(), 0.0) + self.assertEqual(circle.centerData().y(), 10.0) + self.assertEqual(circle.radiusData().value(), 20.0) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/src/PythonAPI/Test/TestSketcherAddLine.py b/src/PythonAPI/Test/TestSketcherAddLine.py index 41322e80f..a0e4a9a28 100644 --- a/src/PythonAPI/Test/TestSketcherAddLine.py +++ b/src/PythonAPI/Test/TestSketcherAddLine.py @@ -2,7 +2,7 @@ import unittest import modeler from TestSketcher import SketcherTestCase -class SketcherAddLineTestCase(SketcherTestCase): +class SketcherAddLine(SketcherTestCase): def runTest(self): line = self.sketch.addLine(0, 0, 0, 1) self.assertEqual(line.startPointData().x(), line.endPointData().x()) diff --git a/src/PythonAPI/Test/TestSketcherSetParallel.py b/src/PythonAPI/Test/TestSketcherSetParallel.py new file mode 100644 index 000000000..d37d02795 --- /dev/null +++ b/src/PythonAPI/Test/TestSketcherSetParallel.py @@ -0,0 +1,12 @@ +import unittest +import modeler +from TestSketcher import SketcherTestCase + +class SketcherSetParallel(SketcherTestCase): + def runTest(self): + l1 = self.sketch.addLine(0, 0, 0, 1) + l2 = self.sketch.addLine(0, 1, 1, 1) + self.sketch.setParallel(l1.result(), l2.result()) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/src/PythonAPI/modeler/sketcher/circle.py b/src/PythonAPI/modeler/sketcher/circle.py index 855651731..08c890bec 100644 --- a/src/PythonAPI/modeler/sketcher/circle.py +++ b/src/PythonAPI/modeler/sketcher/circle.py @@ -1,15 +1,27 @@ +"""Sketch circle feature interface.""" + from GeomDataAPI import geomDataAPI_Point2D -class Circle(): +def addCircle(sketch, x, y, r): + feature = sketch.addFeature("SketchCircle") + return CircleInterface(feature, x, y, r) - def __init__(self, sketch, x, y, r): - self.my = sketch.addFeature("SketchCircle") - geomDataAPI_Point2D( self.my.data().attribute("CircleCenter") ).setValue(x, y) - self.my.data().real("CircleRadius").setValue(r) - self.my.execute() +class CircleInterface(): + def __init__(self, circle_feature, x, y, r): + self._feature = circle_feature + self._center = geomDataAPI_Point2D( + self._feature.data().attribute("CircleCenter") + ) + self._radius = self._feature.data().real("CircleRadius") + self._center.setValue(x, y) + self._radius.setValue(r) + self._feature.execute() - def centerData (self): - return geomDataAPI_Point2D( self.my.data().attribute("CircleCenter") ) + def centerData (self): + return self._center + + def radiusData (self): + return self._radius - def result (self): - return self.my.lastResult() # Returns the circular line attribute + def result (self): + return self._feature.lastResult() # Returns the circular line attribute diff --git a/src/PythonAPI/modeler/sketcher/sketch.py b/src/PythonAPI/modeler/sketcher/sketch.py index 20ddfd842..479bb8c44 100644 --- a/src/PythonAPI/modeler/sketcher/sketch.py +++ b/src/PythonAPI/modeler/sketcher/sketch.py @@ -8,7 +8,7 @@ from GeomDataAPI import * from GeomAlgoAPI import * import modeler.sketcher.point as sk_point import modeler.sketcher.line as sk_line -from modeler.sketcher.circle import Circle +import modeler.sketcher.circle as sk_circle def addSketch(doc, plane): """Add a Sketch feature to the Part or PartSet and return an interface @@ -102,7 +102,8 @@ class Sketch(): def addCircle (self, *args): """Adds a circle to this Sketch.""" - return Circle(self._feature, *args) + circle_interface = sk_circle.addCircle(self._feature, *args) + return circle_interface # Creation of Geometrical and Dimensional Constraints