1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2019 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 class TestKernel(unittest.TestCase):
32 def processGuiEvents(self):
34 if salome.sg.hasDesktop():
35 salome.sg.updateObjBrowser();
37 SalomePyQt.SalomePyQt().processEvents()
39 def test_modulecatalog(self):
40 """Quick test for Kernel module: check module catalogue"""
42 print('Testing Kernel module: check module catalogue')
46 # ---- get module catalogue
47 print('... Get module catalogue')
48 import SALOME_ModuleCatalog
49 obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
50 self.assertIsNotNone(obj)
51 catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
52 self.assertIsNotNone(catalog)
57 # ---- check some catalog's features
58 components = catalog.GetComponentList()
59 self.assertTrue('KERNEL' in components)
60 info = catalog.GetComponentInfo('KERNEL')
61 self.assertEqual(info.name, 'KERNEL')
62 self.assertEqual(info.type, SALOME_ModuleCatalog.OTHER)
64 def test_dataserver(self):
65 """Quick test for Kernel module: check data server"""
67 print('Testing Kernel module: check data server')
71 print('... Initialize study builder')
72 builder = salome.myStudy.NewBuilder()
73 self.assertIsNotNone(builder)
75 print('... Create new component')
76 scomponent = builder.NewComponent('TEST')
77 self.assertIsNotNone(scomponent)
78 self.assertEqual(scomponent.ComponentDataType(), 'TEST')
79 self.assertEqual(scomponent.Depth(), 2)
81 print('...... Assign AttributeName')
82 scomponent.SetAttrString('AttributeName', 'Test')
83 self.assertEqual(scomponent.GetName(), 'Test')
84 self.assertEqual(salome.myStudy.GetObjectPath(scomponent), '/Test')
85 self.processGuiEvents()
87 print('... Create new object')
88 sobject = builder.NewObject(scomponent)
89 self.assertIsNotNone(sobject)
90 self.assertEqual(sobject.Tag(), 1)
91 self.assertEqual(sobject.Depth(), 3)
93 print('...... Get father')
94 father = sobject.GetFatherComponent()
95 self.assertIsNotNone(father)
96 self.assertEqual(father.GetName(), scomponent.GetName())
97 father = sobject.GetFather()
98 self.assertIsNotNone(father)
99 self.assertEqual(father.GetName(), scomponent.GetName())
101 print('...... Assign AttributeName')
102 sobject.SetAttrString('AttributeName', 'Object')
103 self.assertEqual(sobject.GetName(), 'Object')
104 self.assertEqual(salome.myStudy.GetObjectPath(sobject), '/Test/Object')
106 print('...... Assign AttributeInteger')
107 attr = builder.FindOrCreateAttribute(sobject, 'AttributeInteger')
108 self.assertIsNotNone(attr)
110 self.assertEqual(attr.Value(), 123)
111 self.processGuiEvents()
113 if __name__ == '__main__':