Salome HOME
Merge branch 'V9_11_BR'
[modules/kernel.git] / src / KERNEL_PY / kernel_test.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2023  CEA, EDF, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
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.
11 #
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.
16 #
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
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 import unittest
25
26 class TestKernel(unittest.TestCase):
27
28     def setUp(self):
29         import salome
30         salome.salome_init()
31
32     def processGuiEvents(self):
33         import salome
34         if salome.sg.hasDesktop():
35             salome.sg.updateObjBrowser();
36             import SalomePyQt
37             SalomePyQt.SalomePyQt().processEvents()
38
39     def test_modulecatalog(self):
40         """Quick test for Kernel module: check module catalogue"""
41         print()
42         print('Testing Kernel module: check module catalogue')
43
44         import salome
45
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)
53
54         # ---- ping catalog
55         catalog.ping()
56
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)
63             
64     def test_dataserver(self):
65         """Quick test for Kernel module: check data server"""
66         print()
67         print('Testing Kernel module: check data server')
68         
69         import salome
70
71         print('... Initialize study builder')
72         builder = salome.myStudy.NewBuilder()
73         self.assertIsNotNone(builder)
74
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)
80
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()
86
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)
92
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())
100
101         print('...... Assign AttributeName')
102         sobject.SetAttrString('AttributeName', 'Object')
103         self.assertEqual(sobject.GetName(), 'Object')
104         self.assertEqual(salome.myStudy.GetObjectPath(sobject), '/Test/Object')
105
106         print('...... Assign AttributeInteger')
107         attr = builder.FindOrCreateAttribute(sobject, 'AttributeInteger')
108         self.assertIsNotNone(attr)
109         attr.SetValue(123)
110         self.assertEqual(attr.Value(), 123)
111         self.processGuiEvents()
112
113 if __name__ == '__main__':
114     unittest.main()