|
19 | 19 | xldefine, |
20 | 20 | xlclass, |
21 | 21 | VectorError, |
| 22 | + VectorInitializationError, |
| 23 | + VectorOperationError, |
22 | 24 | VectorChannelConfig, |
23 | 25 | ) |
24 | 26 |
|
@@ -285,21 +287,43 @@ def test_called_without_testing_argument(self) -> None: |
285 | 287 | can.Bus(channel=0, bustype="vector") |
286 | 288 |
|
287 | 289 | def test_vector_error_pickle(self) -> None: |
288 | | - error_code = 118 |
289 | | - error_string = "XL_ERROR" |
290 | | - function = "function_name" |
| 290 | + for error_type in [VectorError, VectorInitializationError, VectorOperationError]: |
| 291 | + with self.subTest(f"error_type = {error_type.__name__}"): |
291 | 292 |
|
292 | | - exc = VectorError(error_code, error_string, function) |
| 293 | + error_code = 118 |
| 294 | + error_string = "XL_ERROR" |
| 295 | + function = "function_name" |
293 | 296 |
|
294 | | - # pickle and unpickle |
295 | | - p = pickle.dumps(exc) |
296 | | - exc_unpickled: VectorError = pickle.loads(p) |
| 297 | + exc = error_type(error_code, error_string, function) |
297 | 298 |
|
298 | | - self.assertEqual(str(exc), str(exc_unpickled)) |
299 | | - self.assertEqual(error_code, exc_unpickled.error_code) |
| 299 | + # pickle and unpickle |
| 300 | + p = pickle.dumps(exc) |
| 301 | + exc_unpickled: VectorError = pickle.loads(p) |
300 | 302 |
|
301 | | - with pytest.raises(VectorError): |
302 | | - raise exc_unpickled |
| 303 | + self.assertEqual(str(exc), str(exc_unpickled)) |
| 304 | + self.assertEqual(error_code, exc_unpickled.error_code) |
| 305 | + |
| 306 | + with pytest.raises(error_type): |
| 307 | + raise exc_unpickled |
| 308 | + |
| 309 | + def test_vector_subteype_error_from_generic(self) -> None: |
| 310 | + for error_type in [VectorInitializationError, VectorOperationError]: |
| 311 | + with self.subTest(f"error_type = {error_type.__name__}"): |
| 312 | + |
| 313 | + error_code = 118 |
| 314 | + error_string = "XL_ERROR" |
| 315 | + function = "function_name" |
| 316 | + |
| 317 | + generic = VectorError(error_code, error_string, function) |
| 318 | + |
| 319 | + # pickle and unpickle |
| 320 | + specififc: VectorError = error_type.from_generic(generic) |
| 321 | + |
| 322 | + self.assertEqual(str(generic), str(specififc)) |
| 323 | + self.assertEqual(error_code, specififc.error_code) |
| 324 | + |
| 325 | + with pytest.raises(error_type): |
| 326 | + raise specififc |
303 | 327 |
|
304 | 328 |
|
305 | 329 | class TestVectorChannelConfig: |
|
0 commit comments