2 # Copyright (C) 2019 EfficiOS Inc.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; only version 2
9 # This program 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
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 @unittest.skip("this is broken")
26 class ClockClassPriorityMapTestCase(unittest
.TestCase
):
27 def test_create_empty(self
):
28 cc_prio_map
= bt2
.ClockClassPriorityMap()
29 self
.assertEqual(len(cc_prio_map
), 0)
30 self
.assertIsNone(cc_prio_map
.highest_priority_clock_class
)
32 def test_create_full(self
):
33 cc1
= bt2
.ClockClass('meow', 1234)
34 cc2
= bt2
.ClockClass('mix', 5678)
35 cc_prio_map
= bt2
.ClockClassPriorityMap({cc1
: 17, cc2
: 2})
36 self
.assertEqual(len(cc_prio_map
), 2)
37 self
.assertEqual(cc_prio_map
[cc1
], 17)
38 self
.assertEqual(cc_prio_map
[cc2
], 2)
39 self
.assertEqual(cc_prio_map
.highest_priority_clock_class
, cc2
)
41 def test_setitem(self
):
42 cc_prio_map
= bt2
.ClockClassPriorityMap()
43 cc1
= bt2
.ClockClass('mix', 5678)
44 cc_prio_map
[cc1
] = 184
45 self
.assertEqual(len(cc_prio_map
), 1)
46 self
.assertEqual(cc_prio_map
[cc1
], 184)
47 self
.assertEqual(cc_prio_map
.highest_priority_clock_class
, cc1
)
49 def test_setitem_wrong_key_type(self
):
50 cc_prio_map
= bt2
.ClockClassPriorityMap()
52 with self
.assertRaises(TypeError):
53 cc_prio_map
['the clock'] = 184
55 def test_setitem_wrong_value_type(self
):
56 cc_prio_map
= bt2
.ClockClassPriorityMap()
57 cc1
= bt2
.ClockClass('mix', 5678)
59 with self
.assertRaises(TypeError):
60 cc_prio_map
[cc1
] = 'priority'
62 def test_getitem_wrong_key(self
):
63 cc_prio_map
= bt2
.ClockClassPriorityMap()
64 cc1
= bt2
.ClockClass('mix', 5678)
65 cc2
= bt2
.ClockClass('mix', 5678)
68 with self
.assertRaises(KeyError):
71 def test_getitem_wrong_key_type(self
):
72 cc_prio_map
= bt2
.ClockClassPriorityMap()
74 with self
.assertRaises(TypeError):
78 cc1
= bt2
.ClockClass('meow', 1234)
79 cc2
= bt2
.ClockClass('mix', 5678)
80 cc3
= bt2
.ClockClass('lel', 1548)
81 cc_prio_map
= bt2
.ClockClassPriorityMap({cc1
: 17, cc2
: 2, cc3
: 25})
84 for cc
, prio
in cc_prio_map
.items():
87 self
.assertEqual(len(cc_prios
), 3)
88 self
.assertEqual(cc_prios
[cc1
], 17)
89 self
.assertEqual(cc_prios
[cc2
], 2)
90 self
.assertEqual(cc_prios
[cc3
], 25)
93 cc1
= bt2
.ClockClass('meow', 1234)
94 cc2
= bt2
.ClockClass('mix', 5678)
95 cc3
= bt2
.ClockClass('lel', 1548)
96 cc_prio_map
= bt2
.ClockClassPriorityMap({cc1
: 17, cc2
: 2, cc3
: 25})
97 other_cc1
= bt2
.ClockClass('meow', 1234)
98 other_cc2
= bt2
.ClockClass('mix', 5678)
99 other_cc3
= bt2
.ClockClass('lel', 1548)
100 other_cc_prio_map
= bt2
.ClockClassPriorityMap({other_cc1
: 17, other_cc2
: 2, other_cc3
: 25})
101 self
.assertEqual(cc_prio_map
, other_cc_prio_map
)
103 def test_ne_clock_class(self
):
104 cc1
= bt2
.ClockClass('meow', 1234)
105 cc2
= bt2
.ClockClass('mix', 5678)
106 cc3
= bt2
.ClockClass('lel', 1548)
107 cc_prio_map
= bt2
.ClockClassPriorityMap({cc1
: 17, cc2
: 2, cc3
: 25})
108 other_cc1
= bt2
.ClockClass('meow', 1234)
109 other_cc2
= bt2
.ClockClass('coucou', 5678)
110 other_cc3
= bt2
.ClockClass('lel', 1548)
111 other_cc_prio_map
= bt2
.ClockClassPriorityMap({other_cc1
: 17, other_cc2
: 2, other_cc3
: 25})
112 self
.assertNotEqual(cc_prio_map
, other_cc_prio_map
)
114 def test_ne_prio(self
):
115 cc1
= bt2
.ClockClass('meow', 1234)
116 cc2
= bt2
.ClockClass('mix', 5678)
117 cc3
= bt2
.ClockClass('lel', 1548)
118 cc_prio_map
= bt2
.ClockClassPriorityMap({cc1
: 17, cc2
: 2, cc3
: 25})
119 other_cc1
= bt2
.ClockClass('meow', 1234)
120 other_cc2
= bt2
.ClockClass('mix', 5678)
121 other_cc3
= bt2
.ClockClass('lel', 1548)
122 other_cc_prio_map
= bt2
.ClockClassPriorityMap({other_cc1
: 17, other_cc2
: 3, other_cc3
: 25})
123 self
.assertNotEqual(cc_prio_map
, other_cc_prio_map
)
125 def test_eq_invalid(self
):
126 self
.assertFalse(bt2
.ClockClassPriorityMap() == 23)
129 cc1
= bt2
.ClockClass('meow', 1234)
130 cc2
= bt2
.ClockClass('mix', 5678)
131 cc3
= bt2
.ClockClass('lel', 1548)
132 cc_prio_map
= bt2
.ClockClassPriorityMap({cc1
: 17, cc2
: 2, cc3
: 25})
133 cc_prio_map_cpy
= copy
.copy(cc_prio_map
)
134 self
.assertEqual(cc_prio_map
, cc_prio_map_cpy
)
135 self
.assertEqual(list(cc_prio_map
.keys())[0].addr
, list(cc_prio_map_cpy
.keys())[0].addr
)
136 self
.assertEqual(list(cc_prio_map
.keys())[1].addr
, list(cc_prio_map_cpy
.keys())[1].addr
)
137 self
.assertEqual(list(cc_prio_map
.keys())[2].addr
, list(cc_prio_map_cpy
.keys())[2].addr
)
138 self
.assertEqual(list(cc_prio_map
.values())[0], list(cc_prio_map_cpy
.values())[0])
139 self
.assertEqual(list(cc_prio_map
.values())[1], list(cc_prio_map_cpy
.values())[1])
140 self
.assertEqual(list(cc_prio_map
.values())[2], list(cc_prio_map_cpy
.values())[2])
141 self
.assertEqual(cc_prio_map
.highest_priority_clock_class
.addr
,
142 cc_prio_map_cpy
.highest_priority_clock_class
.addr
)
144 def test_deep_copy(self
):
145 cc1
= bt2
.ClockClass('meow', 1234)
146 cc2
= bt2
.ClockClass('mix', 5678)
147 cc3
= bt2
.ClockClass('lel', 1548)
148 cc_prio_map
= bt2
.ClockClassPriorityMap({cc1
: 17, cc2
: 2, cc3
: 25})
149 cc_prio_map_cpy
= copy
.deepcopy(cc_prio_map
)
150 self
.assertEqual(cc_prio_map
, cc_prio_map_cpy
)
151 self
.assertNotEqual(list(cc_prio_map
.keys())[0].addr
, list(cc_prio_map_cpy
.keys())[0].addr
)
152 self
.assertNotEqual(list(cc_prio_map
.keys())[1].addr
, list(cc_prio_map_cpy
.keys())[1].addr
)
153 self
.assertNotEqual(list(cc_prio_map
.keys())[2].addr
, list(cc_prio_map_cpy
.keys())[2].addr
)
154 self
.assertEqual(list(cc_prio_map
.values())[0], list(cc_prio_map_cpy
.values())[0])
155 self
.assertEqual(list(cc_prio_map
.values())[1], list(cc_prio_map_cpy
.values())[1])
156 self
.assertEqual(list(cc_prio_map
.values())[2], list(cc_prio_map_cpy
.values())[2])
157 self
.assertNotEqual(cc_prio_map
.highest_priority_clock_class
.addr
,
158 cc_prio_map_cpy
.highest_priority_clock_class
.addr
)