| 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 | |
| 19 | import unittest |
| 20 | import uuid |
| 21 | import copy |
| 22 | import bt2 |
| 23 | |
| 24 | |
| 25 | @unittest.skip("this is broken") |
| 26 | class CtfWriterClockTestCase(unittest.TestCase): |
| 27 | def setUp(self): |
| 28 | self._clock = bt2.CtfWriterClock('salut') |
| 29 | |
| 30 | def tearDown(self): |
| 31 | del self._clock |
| 32 | |
| 33 | def test_create_default(self): |
| 34 | self.assertEqual(self._clock.name, 'salut') |
| 35 | |
| 36 | def test_create_invalid_no_name(self): |
| 37 | with self.assertRaises(TypeError): |
| 38 | bt2.CtfWriterClock() |
| 39 | |
| 40 | def test_create_full(self): |
| 41 | my_uuid = uuid.uuid1() |
| 42 | cc = bt2.CtfWriterClock( |
| 43 | name='name', |
| 44 | description='some description', |
| 45 | frequency=1001, |
| 46 | precision=176, |
| 47 | offset=bt2.ClockClassOffset(45, 3003), |
| 48 | is_absolute=True, |
| 49 | uuid=my_uuid, |
| 50 | ) |
| 51 | self.assertEqual(cc.name, 'name') |
| 52 | self.assertEqual(cc.description, 'some description') |
| 53 | self.assertEqual(cc.frequency, 1001) |
| 54 | self.assertEqual(cc.precision, 176) |
| 55 | self.assertEqual(cc.offset, bt2.ClockClassOffset(45, 3003)) |
| 56 | self.assertEqual(cc.is_absolute, True) |
| 57 | self.assertEqual(cc.uuid, copy.deepcopy(my_uuid)) |
| 58 | |
| 59 | def test_assign_description(self): |
| 60 | self._clock.description = 'hi people' |
| 61 | self.assertEqual(self._clock.description, 'hi people') |
| 62 | |
| 63 | def test_assign_invalid_description(self): |
| 64 | with self.assertRaises(TypeError): |
| 65 | self._clock.description = 23 |
| 66 | |
| 67 | def test_assign_frequency(self): |
| 68 | self._clock.frequency = 987654321 |
| 69 | self.assertEqual(self._clock.frequency, 987654321) |
| 70 | |
| 71 | def test_assign_invalid_frequency(self): |
| 72 | with self.assertRaises(TypeError): |
| 73 | self._clock.frequency = 'lel' |
| 74 | |
| 75 | def test_assign_precision(self): |
| 76 | self._clock.precision = 12 |
| 77 | self.assertEqual(self._clock.precision, 12) |
| 78 | |
| 79 | def test_assign_invalid_precision(self): |
| 80 | with self.assertRaises(TypeError): |
| 81 | self._clock.precision = 'lel' |
| 82 | |
| 83 | def test_assign_offset(self): |
| 84 | self._clock.offset = bt2.ClockClassOffset(12, 56) |
| 85 | self.assertEqual(self._clock.offset, bt2.ClockClassOffset(12, 56)) |
| 86 | |
| 87 | def test_assign_invalid_offset(self): |
| 88 | with self.assertRaises(TypeError): |
| 89 | self._clock.offset = object() |
| 90 | |
| 91 | def test_assign_absolute(self): |
| 92 | self._clock.is_absolute = True |
| 93 | self.assertTrue(self._clock.is_absolute) |
| 94 | |
| 95 | def test_assign_invalid_absolute(self): |
| 96 | with self.assertRaises(TypeError): |
| 97 | self._clock.is_absolute = 23 |
| 98 | |
| 99 | def test_assign_uuid(self): |
| 100 | the_uuid = uuid.uuid1() |
| 101 | self._clock.uuid = the_uuid |
| 102 | self.assertEqual(self._clock.uuid, the_uuid) |
| 103 | |
| 104 | def test_assign_invalid_uuid(self): |
| 105 | with self.assertRaises(TypeError): |
| 106 | self._clock.uuid = object() |
| 107 | |
| 108 | def test_assign_time(self): |
| 109 | self._clock.time = 41232 |
| 110 | |
| 111 | def test_assign_invalid_time(self): |
| 112 | with self.assertRaises(TypeError): |
| 113 | self._clock.time = object() |
| 114 | |
| 115 | def _test_copy(self, cpy): |
| 116 | self.assertIsNot(cpy, self._clock) |
| 117 | self.assertNotEqual(cpy.addr, self._clock.addr) |
| 118 | self.assertEqual(cpy, self._clock) |
| 119 | |
| 120 | def test_copy(self): |
| 121 | cpy = copy.copy(self._clock) |
| 122 | self._test_copy(cpy) |
| 123 | |
| 124 | def test_deepcopy(self): |
| 125 | cpy = copy.deepcopy(self._clock) |
| 126 | self._test_copy(cpy) |
| 127 | |
| 128 | def test_eq(self): |
| 129 | my_uuid = uuid.uuid1() |
| 130 | cc1 = bt2.CtfWriterClock( |
| 131 | name='name', |
| 132 | description='some description', |
| 133 | frequency=1001, |
| 134 | precision=176, |
| 135 | offset=bt2.ClockClassOffset(45, 3003), |
| 136 | is_absolute=True, |
| 137 | uuid=my_uuid, |
| 138 | ) |
| 139 | cc2 = bt2.CtfWriterClock( |
| 140 | name='name', |
| 141 | description='some description', |
| 142 | frequency=1001, |
| 143 | precision=176, |
| 144 | offset=bt2.ClockClassOffset(45, 3003), |
| 145 | is_absolute=True, |
| 146 | uuid=my_uuid, |
| 147 | ) |
| 148 | self.assertEqual(cc1, cc2) |
| 149 | |
| 150 | def test_ne_name(self): |
| 151 | my_uuid = uuid.uuid1() |
| 152 | cc1 = bt2.CtfWriterClock( |
| 153 | name='mane', |
| 154 | description='some description', |
| 155 | frequency=1001, |
| 156 | precision=176, |
| 157 | offset=bt2.ClockClassOffset(45, 3003), |
| 158 | is_absolute=True, |
| 159 | uuid=my_uuid, |
| 160 | ) |
| 161 | cc2 = bt2.CtfWriterClock( |
| 162 | name='name', |
| 163 | description='some description', |
| 164 | frequency=1001, |
| 165 | precision=176, |
| 166 | offset=bt2.ClockClassOffset(45, 3003), |
| 167 | is_absolute=True, |
| 168 | uuid=my_uuid, |
| 169 | ) |
| 170 | self.assertNotEqual(cc1, cc2) |
| 171 | |
| 172 | def test_ne_description(self): |
| 173 | my_uuid = uuid.uuid1() |
| 174 | cc1 = bt2.CtfWriterClock( |
| 175 | name='name', |
| 176 | description='some descripti2', |
| 177 | frequency=1001, |
| 178 | precision=176, |
| 179 | offset=bt2.ClockClassOffset(45, 3003), |
| 180 | is_absolute=True, |
| 181 | uuid=my_uuid, |
| 182 | ) |
| 183 | cc2 = bt2.CtfWriterClock( |
| 184 | name='name', |
| 185 | description='some description', |
| 186 | frequency=1001, |
| 187 | precision=176, |
| 188 | offset=bt2.ClockClassOffset(45, 3003), |
| 189 | is_absolute=True, |
| 190 | uuid=my_uuid, |
| 191 | ) |
| 192 | self.assertNotEqual(cc1, cc2) |
| 193 | |
| 194 | def test_ne_frequency(self): |
| 195 | my_uuid = uuid.uuid1() |
| 196 | cc1 = bt2.CtfWriterClock( |
| 197 | name='name', |
| 198 | description='some description', |
| 199 | frequency=1003, |
| 200 | precision=176, |
| 201 | offset=bt2.ClockClassOffset(45, 3003), |
| 202 | is_absolute=True, |
| 203 | uuid=my_uuid, |
| 204 | ) |
| 205 | cc2 = bt2.CtfWriterClock( |
| 206 | name='name', |
| 207 | description='some description', |
| 208 | frequency=1001, |
| 209 | precision=176, |
| 210 | offset=bt2.ClockClassOffset(45, 3003), |
| 211 | is_absolute=True, |
| 212 | uuid=my_uuid, |
| 213 | ) |
| 214 | self.assertNotEqual(cc1, cc2) |
| 215 | |
| 216 | def test_ne_precision(self): |
| 217 | my_uuid = uuid.uuid1() |
| 218 | cc1 = bt2.CtfWriterClock( |
| 219 | name='name', |
| 220 | description='some description', |
| 221 | frequency=1001, |
| 222 | precision=171, |
| 223 | offset=bt2.ClockClassOffset(45, 3003), |
| 224 | is_absolute=True, |
| 225 | uuid=my_uuid, |
| 226 | ) |
| 227 | cc2 = bt2.CtfWriterClock( |
| 228 | name='name', |
| 229 | description='some description', |
| 230 | frequency=1001, |
| 231 | precision=176, |
| 232 | offset=bt2.ClockClassOffset(45, 3003), |
| 233 | is_absolute=True, |
| 234 | uuid=my_uuid, |
| 235 | ) |
| 236 | self.assertNotEqual(cc1, cc2) |
| 237 | |
| 238 | def test_ne_offset(self): |
| 239 | my_uuid = uuid.uuid1() |
| 240 | cc1 = bt2.CtfWriterClock( |
| 241 | name='name', |
| 242 | description='some description', |
| 243 | frequency=1001, |
| 244 | precision=176, |
| 245 | offset=bt2.ClockClassOffset(45, 3001), |
| 246 | is_absolute=True, |
| 247 | uuid=my_uuid, |
| 248 | ) |
| 249 | cc2 = bt2.CtfWriterClock( |
| 250 | name='name', |
| 251 | description='some description', |
| 252 | frequency=1001, |
| 253 | precision=176, |
| 254 | offset=bt2.ClockClassOffset(45, 3003), |
| 255 | is_absolute=True, |
| 256 | uuid=my_uuid, |
| 257 | ) |
| 258 | self.assertNotEqual(cc1, cc2) |
| 259 | |
| 260 | def test_ne_absolute(self): |
| 261 | my_uuid = uuid.uuid1() |
| 262 | cc1 = bt2.CtfWriterClock( |
| 263 | name='name', |
| 264 | description='some description', |
| 265 | frequency=1001, |
| 266 | precision=176, |
| 267 | offset=bt2.ClockClassOffset(45, 3003), |
| 268 | is_absolute=True, |
| 269 | uuid=my_uuid, |
| 270 | ) |
| 271 | cc2 = bt2.CtfWriterClock( |
| 272 | name='name', |
| 273 | description='some description', |
| 274 | frequency=1001, |
| 275 | precision=176, |
| 276 | offset=bt2.ClockClassOffset(45, 3003), |
| 277 | is_absolute=False, |
| 278 | uuid=my_uuid, |
| 279 | ) |
| 280 | self.assertNotEqual(cc1, cc2) |
| 281 | |
| 282 | def test_ne_uuid(self): |
| 283 | cc1 = bt2.CtfWriterClock( |
| 284 | name='name', |
| 285 | description='some description', |
| 286 | frequency=1001, |
| 287 | precision=176, |
| 288 | offset=bt2.ClockClassOffset(45, 3003), |
| 289 | is_absolute=True, |
| 290 | uuid=uuid.uuid1(), |
| 291 | ) |
| 292 | cc2 = bt2.CtfWriterClock( |
| 293 | name='name', |
| 294 | description='some description', |
| 295 | frequency=1001, |
| 296 | precision=176, |
| 297 | offset=bt2.ClockClassOffset(45, 3003), |
| 298 | is_absolute=True, |
| 299 | uuid=uuid.uuid1(), |
| 300 | ) |
| 301 | self.assertNotEqual(cc1, cc2) |
| 302 | |
| 303 | def test_eq_invalid(self): |
| 304 | self.assertFalse(self._clock == 23) |
| 305 | |
| 306 | |
| 307 | if __name__ == '__main__': |
| 308 | unittest.main() |