Fix: flt.lttng-utils.debug-info: possible leak of `bt_message` on error
[babeltrace.git] / tests / bindings / python / bt2 / test_clock_class_priority_map.py
CommitLineData
d2d857a8
MJ
1#
2# Copyright (C) 2019 EfficiOS Inc.
3#
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
7# of the License.
8#
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.
13#
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.
17#
18
811644b8
PP
19import unittest
20import uuid
21import copy
22import bt2
23
24
976c241d 25@unittest.skip("this is broken")
811644b8
PP
26class 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)
31
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)
40
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)
48
49 def test_setitem_wrong_key_type(self):
50 cc_prio_map = bt2.ClockClassPriorityMap()
51
52 with self.assertRaises(TypeError):
53 cc_prio_map['the clock'] = 184
54
55 def test_setitem_wrong_value_type(self):
56 cc_prio_map = bt2.ClockClassPriorityMap()
57 cc1 = bt2.ClockClass('mix', 5678)
58
59 with self.assertRaises(TypeError):
60 cc_prio_map[cc1] = 'priority'
61
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)
66 cc_prio_map[cc1] = 2
67
68 with self.assertRaises(KeyError):
69 cc_prio_map[cc2]
70
71 def test_getitem_wrong_key_type(self):
72 cc_prio_map = bt2.ClockClassPriorityMap()
73
74 with self.assertRaises(TypeError):
75 cc_prio_map[23]
76
77 def test_iter(self):
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})
82 cc_prios = {}
83
84 for cc, prio in cc_prio_map.items():
85 cc_prios[cc] = prio
86
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)
91
92 def test_eq(self):
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)
102
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)
113
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)
124
125 def test_eq_invalid(self):
126 self.assertFalse(bt2.ClockClassPriorityMap() == 23)
127
128 def test_copy(self):
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)
143
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)
This page took 0.040171 seconds and 4 git commands to generate.