diff options
Diffstat (limited to 'bitbake/lib/bb/tests/cow.py')
-rw-r--r-- | bitbake/lib/bb/tests/cow.py | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/cow.py b/bitbake/lib/bb/tests/cow.py new file mode 100644 index 0000000000..599b2aabaf --- /dev/null +++ b/bitbake/lib/bb/tests/cow.py | |||
@@ -0,0 +1,134 @@ | |||
1 | # | ||
2 | # BitBake Tests for Copy-on-Write (cow.py) | ||
3 | # | ||
4 | # Copyright 2006 Holger Freyther <freyther@handhelds.org> | ||
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 version 2 as | ||
8 | # published by the Free Software Foundation. | ||
9 | # | ||
10 | # This program is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License along | ||
16 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | # | ||
19 | |||
20 | import unittest | ||
21 | import os | ||
22 | |||
23 | class COWTestCase(unittest.TestCase): | ||
24 | """ | ||
25 | Test case for the COW module from mithro | ||
26 | """ | ||
27 | |||
28 | def testGetSet(self): | ||
29 | """ | ||
30 | Test and set | ||
31 | """ | ||
32 | from bb.COW import COWDictBase | ||
33 | a = COWDictBase.copy() | ||
34 | |||
35 | self.assertEquals(False, a.has_key('a')) | ||
36 | |||
37 | a['a'] = 'a' | ||
38 | a['b'] = 'b' | ||
39 | self.assertEquals(True, a.has_key('a')) | ||
40 | self.assertEquals(True, a.has_key('b')) | ||
41 | self.assertEquals('a', a['a'] ) | ||
42 | self.assertEquals('b', a['b'] ) | ||
43 | |||
44 | def testCopyCopy(self): | ||
45 | """ | ||
46 | Test the copy of copies | ||
47 | """ | ||
48 | |||
49 | from bb.COW import COWDictBase | ||
50 | |||
51 | # create two COW dict 'instances' | ||
52 | b = COWDictBase.copy() | ||
53 | c = COWDictBase.copy() | ||
54 | |||
55 | # assign some keys to one instance, some keys to another | ||
56 | b['a'] = 10 | ||
57 | b['c'] = 20 | ||
58 | c['a'] = 30 | ||
59 | |||
60 | # test separation of the two instances | ||
61 | self.assertEquals(False, c.has_key('c')) | ||
62 | self.assertEquals(30, c['a']) | ||
63 | self.assertEquals(10, b['a']) | ||
64 | |||
65 | # test copy | ||
66 | b_2 = b.copy() | ||
67 | c_2 = c.copy() | ||
68 | |||
69 | self.assertEquals(False, c_2.has_key('c')) | ||
70 | self.assertEquals(10, b_2['a']) | ||
71 | |||
72 | b_2['d'] = 40 | ||
73 | self.assertEquals(False, c_2.has_key('d')) | ||
74 | self.assertEquals(True, b_2.has_key('d')) | ||
75 | self.assertEquals(40, b_2['d']) | ||
76 | self.assertEquals(False, b.has_key('d')) | ||
77 | self.assertEquals(False, c.has_key('d')) | ||
78 | |||
79 | c_2['d'] = 30 | ||
80 | self.assertEquals(True, c_2.has_key('d')) | ||
81 | self.assertEquals(True, b_2.has_key('d')) | ||
82 | self.assertEquals(30, c_2['d']) | ||
83 | self.assertEquals(40, b_2['d']) | ||
84 | self.assertEquals(False, b.has_key('d')) | ||
85 | self.assertEquals(False, c.has_key('d')) | ||
86 | |||
87 | # test copy of the copy | ||
88 | c_3 = c_2.copy() | ||
89 | b_3 = b_2.copy() | ||
90 | b_3_2 = b_2.copy() | ||
91 | |||
92 | c_3['e'] = 4711 | ||
93 | self.assertEquals(4711, c_3['e']) | ||
94 | self.assertEquals(False, c_2.has_key('e')) | ||
95 | self.assertEquals(False, b_3.has_key('e')) | ||
96 | self.assertEquals(False, b_3_2.has_key('e')) | ||
97 | self.assertEquals(False, b_2.has_key('e')) | ||
98 | |||
99 | b_3['e'] = 'viel' | ||
100 | self.assertEquals('viel', b_3['e']) | ||
101 | self.assertEquals(4711, c_3['e']) | ||
102 | self.assertEquals(False, c_2.has_key('e')) | ||
103 | self.assertEquals(True, b_3.has_key('e')) | ||
104 | self.assertEquals(False, b_3_2.has_key('e')) | ||
105 | self.assertEquals(False, b_2.has_key('e')) | ||
106 | |||
107 | def testCow(self): | ||
108 | from bb.COW import COWDictBase | ||
109 | c = COWDictBase.copy() | ||
110 | c['123'] = 1027 | ||
111 | c['other'] = 4711 | ||
112 | c['d'] = { 'abc' : 10, 'bcd' : 20 } | ||
113 | |||
114 | copy = c.copy() | ||
115 | |||
116 | self.assertEquals(1027, c['123']) | ||
117 | self.assertEquals(4711, c['other']) | ||
118 | self.assertEquals({'abc':10, 'bcd':20}, c['d']) | ||
119 | self.assertEquals(1027, copy['123']) | ||
120 | self.assertEquals(4711, copy['other']) | ||
121 | self.assertEquals({'abc':10, 'bcd':20}, copy['d']) | ||
122 | |||
123 | # cow it now | ||
124 | copy['123'] = 1028 | ||
125 | copy['other'] = 4712 | ||
126 | copy['d']['abc'] = 20 | ||
127 | |||
128 | |||
129 | self.assertEquals(1027, c['123']) | ||
130 | self.assertEquals(4711, c['other']) | ||
131 | self.assertEquals({'abc':10, 'bcd':20}, c['d']) | ||
132 | self.assertEquals(1028, copy['123']) | ||
133 | self.assertEquals(4712, copy['other']) | ||
134 | self.assertEquals({'abc':20, 'bcd':20}, copy['d']) | ||