Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / test.hdfs / test_hdf.py
1 # Copyright (C) 2014-2020  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 salome, salome_utils, os, sys
21 import SalomePyQt
22
23 import unittest
24 import subprocess
25
26 import ModelHighAPI, ModelAPI, PartSetAPI
27 from GeomAPI import GeomAPI_Shape
28 from salome.shaper import model
29
30 class TestHDF(unittest.TestCase):
31   testfile = ""
32   reffile = ""
33
34   def setUp(self):
35     salome.salome_close()
36
37     # leave file name only (trim path and extension)
38     fileName = os.path.basename(self.testfile)
39     self.reffile = self.reffile + "/" + os.path.splitext(fileName)[0] + ".py"
40
41     salome.salome_init(self.testfile, embedded=1)
42     myStudyName = salome.myStudy._get_Name()
43     self.session = salome.naming_service.Resolve('/Kernel/Session')
44     self.session.emitMessage("connect_to_study")
45
46     self.sg = SalomePyQt.SalomePyQt()
47     self.sg.activateModule("Shaper")
48     self.session = ModelAPI.ModelAPI_Session.get()
49     self.partSet = self.session.moduleDocument()
50
51   def tearDown(self):
52     salome.sg.UpdateView()
53     self.sg.processEvents()
54     salome.sg.FitAll()
55
56   def test_hdf_file(self):
57     self.assertTrue(self.partSet.size("Parts") > 0)
58     aPartsList = dict()
59     for aPartIndex in range(self.partSet.size("Parts")):
60       self.session.startOperation()
61       aPart = ModelAPI.modelAPI_ResultPart(ModelAPI.objectToResult(self.partSet.object("Parts", aPartIndex)))
62       aPart.activate()
63       self.session.finishOperation()
64
65       aPartFeature = PartSetAPI.PartSetAPI_Part(self.partSet.currentFeature(True))
66       aPartsList["Part_{}".format(aPartIndex+1)] = aPartFeature
67
68       self.session.startOperation()
69       self.session.setActiveDocument(self.partSet)
70       self.session.finishOperation()
71
72     # check reference data
73     exec(open(self.reffile, "rb").read(), globals(), aPartsList)
74
75
76 if __name__ == "__main__":
77   if len(sys.argv) > 1:
78     TestHDF.testfile = sys.argv[1]
79   if len(sys.argv) > 2:
80     salomePortFile = sys.argv[2]
81   if len(sys.argv) > 3:
82     errFile = open(sys.argv[3], 'w')
83   if len(sys.argv) > 4:
84     salomeKernelDir = sys.argv[4]
85   if len(sys.argv) > 5:
86     TestHDF.reffile = sys.argv[5]
87
88   aTest = unittest.TestLoader().loadTestsFromTestCase(TestHDF)
89   unittest.TextTestRunner(stream=errFile).run(aTest)
90   errFile.close()
91
92   # close Salome GUI
93   port = salome_utils.getPortNumber()
94   proc = subprocess.Popen([salomeKernelDir + "/bin/salome/killSalomeWithPort.py", "{}".format(port)])
95
96   try:
97     os.remove(salomePortFile)
98   except:
99     print("Cannot remove file", file=f)