Creating new branch nepi-3.1-multirun
[nepi.git] / test / design / box.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20
21
22 from nepi.design.box import Box 
23
24 import unittest
25
26 class BoxDesignTestCase(unittest.TestCase):
27     def test_simple_design(self):
28         node1 = Box()
29         node2 = Box()
30
31         node1.label = "uno"
32         node2.label = "dos"
33
34         node1.tadd('nodo')
35         node2.tadd('mynodo')
36
37         self.assertEquals(node1.tags, set(['nodo']))
38         self.assertEquals(node2.tags, set(['mynodo']))
39        
40         node1.a.hola = "chau"
41         node2.a.hello = "bye"
42
43         self.assertEquals(node1.a.hola, "chau")
44         self.assertEquals(node2.a.hello, "bye")
45
46         node1.connect(node2)
47         
48         self.assertEquals(node1.connections, set([node2]))
49         self.assertEquals(node2.connections, set([node1]))
50         self.assertTrue(node1.is_connected(node2))
51         self.assertTrue(node2.is_connected(node1))
52
53         self.assertEquals(node1.c.dos.a.hello, "bye")
54         self.assertEquals(node2.c.uno.a.hola, "chau")
55        
56         node2.disconnect(node1)
57
58         self.assertEquals(node1.connections, set([]))
59         self.assertEquals(node2.connections, set([]))
60         self.assertFalse(node1.is_connected(node2))
61         self.assertFalse(node2.is_connected(node1))
62
63         self.assertRaises(AttributeError, node1.c.dos)
64         self.assertRaises(AttributeError, node2.c.uno)
65
66
67 if __name__ == '__main__':
68     unittest.main()
69