Salome HOME
a3028f70380f4ad5a0564ceddc67a99c864a1d60
[modules/shaper.git] / src / PythonAPI / Test / TestFeatures.py
1 # Copyright (C) 2014-2023  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 email : webmaster.salome@opencascade.com
18 #
19
20 import unittest
21
22 import ModelAPI
23
24 from salome.shaper import model
25
26 #-----------------------------------------------------------------------------
27 # Fixtures
28
29 class FeaturesFixture(unittest.TestCase):
30
31     def setUp(self):
32         model.begin()
33         # Create part
34         partset = model.moduleDocument()
35         self.part = model.addPart(partset).document()
36         model.do()
37
38     def tearDown(self):
39         model.end()
40         # assert(model.checkPythonDump())
41         # This test checks creation of High API classes from low-level.
42         # It does not set any attributes, so features invalid, and dump also invalid.
43         model.reset()
44
45 #-----------------------------------------------------------------------------
46 # TestCases
47
48 class FeaturesTestCase(FeaturesFixture):
49
50     # def test_assert_error_on_empty_args(self):
51     #     features = [
52     #         # Implemented in C++, add* without arguments doesn't exist
53     #         # "addPoint", "addPlane",
54     #         # "addImport", "exportToFile",
55     #
56     #         "addAxis",
57     #         "addCut", "addFuse", "addCommon",
58     #         "addExtrusion",
59     #         # "addExtrusionCut", "addExtrusionFuse",
60     #         "addRevolution",
61     #         # "addRevolutionCut", "addRevolutionFuse",
62     #         "addPlacement", "addRotation", "addTranslation",
63     #         "addGroup",
64     #         "addParameter",
65     #         ]
66     #     for name in features:
67     #         try:
68     #             with self.assertRaises(AssertionError):
69     #                 feature = getattr(model, name)(self.part)
70     #         except AssertionError as e:
71     #             self.fail("%s does not check empty args" % name)
72
73     def test_addPoint(self):
74         model.addPoint(self.part, 10, "20", "x + 30")
75
76     def test_initialize_without_attributes(self):
77         import ConstructionAPI
78         ConstructionAPI.ConstructionAPI_Axis(self.part.addFeature("Axis"))
79         ConstructionAPI.ConstructionAPI_Plane(self.part.addFeature("Plane"))
80         ConstructionAPI.ConstructionAPI_Point(self.part.addFeature("Point"))
81
82         import ExchangeAPI
83         ExchangeAPI.ExchangeAPI_Import(self.part.addFeature("Import"))
84
85         import FeaturesAPI
86         FeaturesAPI.FeaturesAPI_BooleanCut(self.part.addFeature("BooleanCut"))
87         FeaturesAPI.FeaturesAPI_BooleanFuse(self.part.addFeature("BooleanFuse"))
88         FeaturesAPI.FeaturesAPI_BooleanCommon(self.part.addFeature("BooleanCommon"))
89         FeaturesAPI.FeaturesAPI_BooleanFill(self.part.addFeature("BooleanFill"))
90         FeaturesAPI.FeaturesAPI_BooleanSmash(self.part.addFeature("BooleanSmash"))
91         FeaturesAPI.FeaturesAPI_Extrusion(self.part.addFeature("Extrusion"))
92         FeaturesAPI.FeaturesAPI_ExtrusionCut(self.part.addFeature("ExtrusionCut"))
93         FeaturesAPI.FeaturesAPI_ExtrusionFuse(self.part.addFeature("ExtrusionFuse"))
94         FeaturesAPI.FeaturesAPI_Revolution(self.part.addFeature("Revolution"))
95         FeaturesAPI.FeaturesAPI_RevolutionCut(self.part.addFeature("RevolutionCut"))
96         FeaturesAPI.FeaturesAPI_RevolutionFuse(self.part.addFeature("RevolutionFuse"))
97         FeaturesAPI.FeaturesAPI_Placement(self.part.addFeature("Placement"))
98         FeaturesAPI.FeaturesAPI_Rotation(self.part.addFeature("Rotation"))
99         FeaturesAPI.FeaturesAPI_Translation(self.part.addFeature("Translation"))
100
101         import CollectionAPI
102         CollectionAPI.CollectionAPI_Group(self.part.addFeature("Group"))
103
104         import PrimitivesAPI
105         PrimitivesAPI.PrimitivesAPI_Box(self.part.addFeature("Box"))
106
107         import ParametersAPI
108         ParametersAPI.ParametersAPI_Parameter(self.part.addFeature("Parameter"))
109
110 #-----------------------------------------------------------------------------
111
112 if __name__ == "__main__":
113     test_program = unittest.main(exit=False)
114     assert test_program.result.wasSuccessful(), "Test failed"