Skip to content

Commit 5b8c43c

Browse files
committed
Add test cases for new error vector types
1 parent ed107af commit 5b8c43c

1 file changed

Lines changed: 35 additions & 11 deletions

File tree

test/test_vector.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
xldefine,
2020
xlclass,
2121
VectorError,
22+
VectorInitializationError,
23+
VectorOperationError,
2224
VectorChannelConfig,
2325
)
2426

@@ -285,21 +287,43 @@ def test_called_without_testing_argument(self) -> None:
285287
can.Bus(channel=0, bustype="vector")
286288

287289
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__}"):
291292

292-
exc = VectorError(error_code, error_string, function)
293+
error_code = 118
294+
error_string = "XL_ERROR"
295+
function = "function_name"
293296

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)
297298

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)
300302

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
303327

304328

305329
class TestVectorChannelConfig:

0 commit comments

Comments
 (0)