Skip to content

Allow ICSApiError to be pickled and un-pickled #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions can/interfaces/ics_neovi/neovi_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def __init__(
self.severity = severity
self.restart_needed = restart_needed == 1

def __reduce__(self):
return type(self), (
self.error_code,
self.description_short,
self.description_long,
self.severity,
self.restart_needed,
)

@property
def error_number(self) -> int:
"""Deprecated. Renamed to :attr:`can.CanError.error_code`."""
Expand Down
25 changes: 25 additions & 0 deletions test/test_neovi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

"""
"""
import pickle
import unittest
from can.interfaces.ics_neovi import ICSApiError


class ICSApiErrorTest(unittest.TestCase):
def test_error_pickling(self):
iae = ICSApiError(
0xF00,
"description_short",
"description_long",
severity=ICSApiError.ICS_SPY_ERR_CRITICAL,
restart_needed=1,
)
pickled_iae = pickle.dumps(iae)
un_pickled_iae = pickle.loads(pickled_iae)
assert iae.__dict__ == un_pickled_iae.__dict__


if __name__ == "__main__":
unittest.main()