Salome HOME
Increment version: 7.6.0
[modules/kernel.git] / src / SALOMESDS / TestSalomeSDS2.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay
21
22 import SalomeSDSClt
23 import SALOME
24 import salome
25 import unittest
26 import gc
27
28 class SalomeSDS2Test(unittest.TestCase):
29   
30   def testList1(self):
31     a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0")
32     self.assertEqual(a.local_copy(),[])
33     a.append(5)
34     self.assertEqual(a.local_copy(),[5])
35     self.assertRaises(SALOME.SALOME_Exception,a.__delitem__,0)
36     a.append(["rt"])
37     self.assertEqual(a.local_copy(),[5,["rt"]])
38     a[1].append(8)
39     self.assertEqual(a.local_copy(),[5,["rt",8]])
40     a.extend(a)
41     self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8]])
42     a.extend(a[3:])
43     self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8]])
44     a[4].append(7)
45     self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]])
46     a._var_ptr.getMyDataScopeServer().deleteVar("a")
47     pass
48   
49   def testDict1(self):
50     a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0")
51     a["ab"]=4
52     self.assertEqual(a.local_copy(),{"ab":4})
53     a["cd"]=[5]
54     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]})
55     a["cd"].append(77)
56     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
57     a.__setitem__("ef",["a","bb"])
58     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]})
59     self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb"])
60     self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb","ccc"])
61     a["ef"].append("ccc")
62     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]})
63     a["gh"]=a
64     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}})
65     a["gh"]["cd"].append(99) ; a["cd"].append(88)
66     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
67     a._var_ptr.getMyDataScopeServer().deleteVar("a")
68     pass
69
70   def testReadOnly1(self):
71     a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a","Scope0")
72     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
73     self.assertRaises(AttributeError,a.__getitem__,"ab")
74     a._var_ptr.getMyDataScopeServer().deleteVar("a")
75
76   def setUp(self):
77     salome.salome_init()
78     pass
79   
80   pass
81
82 unittest.main()
83