Skip to content

Commit

Permalink
possible fix and test for #381
Browse files Browse the repository at this point in the history
  • Loading branch information
Bröcker committed Aug 6, 2019
1 parent c7f1a48 commit eaeab8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import canmatrix.copy
import canmatrix.types
import canmatrix.utils
import copy

if attr.__version__ < '17.4.0': # type: ignore
raise RuntimeError("need attrs >= 17.4.0")
Expand All @@ -69,8 +68,8 @@ class J1939needsExtendedIdetifier(ExceptionTemplate): pass

def arbitration_id_converter(source): # type: (typing.Union[int, ArbitrationId]) -> ArbitrationId
"""Converter for attrs which accepts ArbitrationId itself or int."""
temp_id = source if isinstance(source, ArbitrationId) else ArbitrationId.from_compound_integer(source)
return copy.deepcopy(temp_id)
return source if isinstance(source, ArbitrationId) else ArbitrationId.from_compound_integer(source)


@attr.s
class Ecu(object):
Expand Down Expand Up @@ -721,7 +720,7 @@ class Frame(object):

name = attr.ib(default="") # type: str
# mypy Unsupported converter:
arbitration_id = attr.ib(converter=arbitration_id_converter, default=arbitration_id_converter(0)) # type: ArbitrationId
arbitration_id = attr.ib(converter=arbitration_id_converter, default=0) # type: ArbitrationId
size = attr.ib(default=0) # type: int
transmitters = attr.ib(factory=list) # type: typing.MutableSequence[str]
# extended = attr.ib(default=False) # type: bool
Expand Down
10 changes: 10 additions & 0 deletions src/canmatrix/tests/test_canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,16 @@ def test_Arbitration_id():
assert id_from_int_extended == id_extended
assert id_from_int_extended != id_standard

def test_arbitration_id_is_instance():
frame1 = canmatrix.Frame(name = "Frame1")
frame2 = canmatrix.Frame(name = "Frame1")

frame1.arbitration_id.id = 42

assert frame1.arbitration_id.id == 42
assert frame2.arbitration_id.id == 0



@pytest.fixture
def empty_matrix():
Expand Down

0 comments on commit eaeab8e

Please sign in to comment.