1 # Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 import salome, os, sys
26 import ModelHighAPI, ModelAPI, PartSetAPI
27 from GeomAPI import GeomAPI_Shape
28 from salome.shaper import model
30 class TestHDF(unittest.TestCase):
35 # ===========================================
36 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
37 print(" UnitTest setUp() started", file=dbgFile)
39 # ===========================================
41 # ===========================================
42 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
43 print(" UnitTest previous session closed", file=dbgFile)
45 # ===========================================
47 # leave file name only (trim path and extension)
48 fileName = os.path.basename(self.testfile)
49 self.reffile = self.reffile + "/" + os.path.splitext(fileName)[0] + ".py"
50 # ===========================================
51 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
52 print(" UnitTest reffile: {}".format(self.reffile), file=dbgFile)
54 # ===========================================
56 salome.salome_init(self.testfile, embedded=1)
57 myStudyName = salome.myStudy._get_Name()
58 self.session = salome.naming_service.Resolve('/Kernel/Session')
59 self.session.emitMessage("connect_to_study")
60 # ===========================================
61 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
62 print(" UnitTest Salome started", file=dbgFile)
64 # ===========================================
66 self.sg = SalomePyQt.SalomePyQt()
67 self.sg.activateModule("Shaper")
68 self.session = ModelAPI.ModelAPI_Session.get()
69 self.partSet = self.session.moduleDocument()
70 # ===========================================
71 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
72 print(" UnitTest Shaper started", file=dbgFile)
74 # ===========================================
77 # ===========================================
78 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
79 print(" UnitTest tearDown() started", file=dbgFile)
81 # ===========================================
82 salome.sg.UpdateView()
83 self.sg.processEvents()
85 # ===========================================
86 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
87 print(" UnitTest tearDown() finished", file=dbgFile)
89 # ===========================================
91 def test_hdf_file(self):
92 # ===========================================
93 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
94 print(" UnitTest start HDF file testing", file=dbgFile)
96 # ===========================================
97 self.assertTrue(self.partSet.size("Parts") > 0)
98 # ===========================================
99 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
100 print(" UnitTest number of parts: {}".format(self.partSet.size("Parts")), file=dbgFile)
102 # ===========================================
104 for aPartIndex in range(self.partSet.size("Parts")):
105 self.session.startOperation()
106 aPart = ModelAPI.modelAPI_ResultPart(ModelAPI.objectToResult(self.partSet.object("Parts", aPartIndex)))
108 self.session.finishOperation()
110 # ===========================================
111 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
112 print(" UnitTest test part: {}".format(aPartIndex), file=dbgFile)
114 # ===========================================
115 aPartFeature = PartSetAPI.PartSetAPI_Part(self.partSet.currentFeature(True))
116 # check reference data
117 exec(open(self.reffile, "rb").read())
118 # ===========================================
119 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
120 print(" UnitTest test part finished", file=dbgFile)
122 # ===========================================
125 if __name__ == "__main__":
126 if len(sys.argv) > 1:
127 TestHDF.testfile = sys.argv[1]
128 if len(sys.argv) > 2:
129 salomePortFile = sys.argv[2]
130 if len(sys.argv) > 3:
131 errFile = open(sys.argv[3], 'w')
132 if len(sys.argv) > 4:
133 salomeKernelDir = sys.argv[4]
134 if len(sys.argv) > 5:
135 TestHDF.reffile = sys.argv[5]
137 # ===========================================
138 dbgFile = open(os.getcwd() + "/dbgfile", 'a')
139 print(" UnitTest started with parameters:", file=dbgFile)
140 print(" testfile: {}".format(TestHDF.testfile), file=dbgFile)
141 print(" salomePortFile: {}".format(salomePortFile), file=dbgFile)
142 print(" salomeKernelDir: {}".format(salomeKernelDir), file=dbgFile)
143 print(" reffile: {}".format(TestHDF.reffile), file=dbgFile)
145 # ===========================================
146 aTest = unittest.TestLoader().loadTestsFromTestCase(TestHDF)
147 unittest.TextTestRunner(stream=errFile).run(aTest)
150 # test_program = unittest.main(argv=[sys.argv[0]], exit=False)
151 proc = subprocess.Popen(salomeKernelDir + "/bin/salome/killSalome.py")
154 os.remove(salomePortFile)
156 print("Cannot remove file", file=f)
158 # assert test_program.result.wasSuccessful(), "Test failed"