]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/Test/TestFeaturesRevolution.py
Salome HOME
Update incorrect units tests and add missing tests (issues #2838, #2839, #2840, ...
[modules/shaper.git] / src / PythonAPI / Test / TestFeaturesRevolution.py
1 ## Copyright (C) 2014-2017  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 import unittest
22
23 import ModelAPI
24
25 from salome.shaper import model
26
27 #-----------------------------------------------------------------------------
28 # Fixtures
29
30 class FeaturesAddRevolutionFixture(unittest.TestCase):
31
32     def setUp(self):
33         model.begin()
34         # Create part
35         partset = model.moduleDocument()
36         self.part = model.addPart(partset).document()
37         model.do()
38
39     def tearDown(self):
40         model.end()
41         assert(model.checkPythonDump())
42         model.reset()
43
44
45 class FeaturesRevolutionFixture(FeaturesAddRevolutionFixture):
46
47     def setUp(self):
48         FeaturesAddRevolutionFixture.setUp(self)
49         # Create revolution
50         # base
51         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
52         circle = base_sketch.addCircle(0, 0, 10)
53
54         model.do()
55
56         base = base_sketch.selectFace()
57         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
58         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
59         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
60
61         self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
62
63         model.do()
64
65     def tearDown(self):
66         FeaturesAddRevolutionFixture.tearDown(self)
67
68 #-----------------------------------------------------------------------------
69 # TestCases
70
71 class FeaturesAddRevolutionTestCase(FeaturesAddRevolutionFixture):
72
73     def test_add_revolution_by_face_and_angles(self):
74         # base
75         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
76         circle = base_sketch.addCircle(0, 0, 10)
77
78         model.do()
79
80         base = base_sketch.selectFace()
81         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
82         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
83         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
84
85         revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
86
87         self.assertEqual(revolution.creationMethod().value(), "ByAngles")
88         self.assertEqual(revolution.toAngle().value(), 0)
89         self.assertEqual(revolution.fromAngle().value(), 180)
90         self.assertEqual(revolution.toObject().context(), None)
91         self.assertEqual(revolution.fromObject().context(), None)
92
93     def test_add_revolution_by_face_and_planes(self):
94         # base
95         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
96         base_circle = base_sketch.addCircle(0, 0, 10)
97         # to
98         to_plane = model.defaultPlane("XOY")
99         to_plane.origin().setZ(10)
100         to_sketch = model.addSketch(self.part, to_plane)
101         to_circle = to_sketch.addCircle(0, 0, 10)
102         # from
103         from_plane = model.defaultPlane("XOY")
104         from_plane.origin().setZ(-10)
105         from_sketch = model.addSketch(self.part, from_plane)
106         from_circle = from_sketch.addCircle(0, 0, 10)
107
108         model.do()
109
110         base = base_sketch.selectFace()
111         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
112         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
113         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
114         to_obejct = to_sketch.selectFace()[0]
115         from_object = from_sketch.selectFace()[0]
116
117         self.revolution = model.addRevolution(self.part, base, axis_object,
118                                               to_obejct, 15,
119                                               from_object, 20)
120
121         self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets")
122         self.assertNotEqual(self.revolution.toObject().context(), None)
123         self.assertEqual(self.revolution.toOffset().value(), 15)
124         self.assertNotEqual(self.revolution.fromObject().context(), None)
125         self.assertEqual(self.revolution.fromOffset().value(), 20)
126
127
128 class FeaturesRevolutionTestCase(FeaturesRevolutionFixture):
129
130     def test_revolution_feature_calls(self):
131         # call method of the feature
132         self.assertEqual(self.revolution.getKind(), "Revolution")
133
134     def test_revolution_get_attribute(self):
135         # call method of the feature
136         self.assertTrue(isinstance(self.revolution.baseObjects(),
137                                    ModelAPI.ModelAPI_AttributeSelectionList))
138         self.assertTrue(isinstance(self.revolution.axis(),
139                                    ModelAPI.ModelAPI_AttributeSelection))
140         self.assertTrue(isinstance(self.revolution.creationMethod(),
141                                    ModelAPI.ModelAPI_AttributeString))
142         self.assertTrue(isinstance(self.revolution.toAngle(),
143                                    ModelAPI.ModelAPI_AttributeDouble))
144         self.assertTrue(isinstance(self.revolution.fromAngle(),
145                                    ModelAPI.ModelAPI_AttributeDouble))
146         self.assertTrue(isinstance(self.revolution.toObject(),
147                                    ModelAPI.ModelAPI_AttributeSelection))
148         self.assertTrue(isinstance(self.revolution.toOffset(),
149                                    ModelAPI.ModelAPI_AttributeDouble))
150         self.assertTrue(isinstance(self.revolution.fromObject(),
151                                    ModelAPI.ModelAPI_AttributeSelection))
152         self.assertTrue(isinstance(self.revolution.fromOffset(),
153                                    ModelAPI.ModelAPI_AttributeDouble))
154
155     def test_revolution_set_angles(self):
156         self.revolution.setAngles(90, 270)
157         self.assertEqual(self.revolution.creationMethod().value(), "ByAngles")
158         self.assertEqual(self.revolution.toAngle().value(), 90)
159         self.assertEqual(self.revolution.fromAngle().value(), 270)
160         self.assertEqual(self.revolution.toObject().context(), None)
161         self.assertEqual(self.revolution.fromObject().context(), None)
162
163     def test_revolution_set_planes_and_offsets(self):
164         # base
165         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
166         base_circle = base_sketch.addCircle(0, 0, 10)
167         # to
168         to_plane = model.defaultPlane("XOY")
169         to_plane.origin().setZ(10)
170         to_sketch = model.addSketch(self.part, to_plane)
171         to_circle = to_sketch.addCircle(0, 0, 10)
172         # from
173         from_plane = model.defaultPlane("XOY")
174         from_plane.origin().setZ(-10)
175         from_sketch = model.addSketch(self.part, from_plane)
176         from_circle = from_sketch.addCircle(0, 0, 10)
177
178         model.do()
179
180         base = base_sketch.selectFace()
181         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
182         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
183         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
184         to_obejct = to_sketch.selectFace()[0]
185         from_object = from_sketch.selectFace()[0]
186
187         self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
188         self.revolution.setPlanesAndOffsets(to_obejct, 15, from_object, 20)
189
190         self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets")
191         self.assertNotEqual(self.revolution.toObject().context(), None)
192         self.assertEqual(self.revolution.toOffset().value(), 15)
193         self.assertNotEqual(self.revolution.fromObject().context(), None)
194         self.assertEqual(self.revolution.fromOffset().value(), 20)
195
196
197 if __name__ == "__main__":
198     test_program = unittest.main(exit=False)
199     assert test_program.result.wasSuccessful(), "Test failed"