Show More
@@ -0,0 +1,67 b'' | |||
|
1 | #!/usr/bin/env python | |
|
2 | # encoding: utf-8 | |
|
3 | """ | |
|
4 | Tests for IPython.core.component | |
|
5 | ||
|
6 | Authors: | |
|
7 | ||
|
8 | * Brian Granger | |
|
9 | * Fernando Perez (design help) | |
|
10 | """ | |
|
11 | ||
|
12 | #----------------------------------------------------------------------------- | |
|
13 | # Copyright (C) 2008-2009 The IPython Development Team | |
|
14 | # | |
|
15 | # Distributed under the terms of the BSD License. The full license is in | |
|
16 | # the file COPYING, distributed as part of this software. | |
|
17 | #----------------------------------------------------------------------------- | |
|
18 | ||
|
19 | #----------------------------------------------------------------------------- | |
|
20 | # Imports | |
|
21 | #----------------------------------------------------------------------------- | |
|
22 | ||
|
23 | from unittest import TestCase | |
|
24 | ||
|
25 | from IPython.core.component import Component | |
|
26 | ||
|
27 | ||
|
28 | #----------------------------------------------------------------------------- | |
|
29 | # Test cases | |
|
30 | #----------------------------------------------------------------------------- | |
|
31 | ||
|
32 | ||
|
33 | class TestComponentMeta(TestCase): | |
|
34 | ||
|
35 | def test_get_instances(self): | |
|
36 | class BaseComponent(Component): | |
|
37 | pass | |
|
38 | c1 = BaseComponent(None) | |
|
39 | c2 = BaseComponent(c1) | |
|
40 | self.assertEquals(BaseComponent.get_instances(),[c1,c2]) | |
|
41 | ||
|
42 | ||
|
43 | class TestComponent(TestCase): | |
|
44 | ||
|
45 | def test_parent_child(self): | |
|
46 | c1 = Component(None) | |
|
47 | c2 = Component(c1) | |
|
48 | c3 = Component(c1) | |
|
49 | c4 = Component(c3) | |
|
50 | self.assertEquals(c1.parent, None) | |
|
51 | self.assertEquals(c2.parent, c1) | |
|
52 | self.assertEquals(c3.parent, c1) | |
|
53 | self.assertEquals(c4.parent, c3) | |
|
54 | self.assertEquals(c1.children, [c2, c3]) | |
|
55 | self.assertEquals(c2.children, []) | |
|
56 | self.assertEquals(c3.children, [c4]) | |
|
57 | self.assertEquals(c4.children, []) | |
|
58 | ||
|
59 | def test_root(self): | |
|
60 | c1 = Component(None) | |
|
61 | c2 = Component(c1) | |
|
62 | c3 = Component(c1) | |
|
63 | c4 = Component(c3) | |
|
64 | self.assertEquals(c1.root, c1.root) | |
|
65 | self.assertEquals(c2.root, c1) | |
|
66 | self.assertEquals(c3.root, c1) | |
|
67 | self.assertEquals(c4.root, c1) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now