Skip to content

Commit 77fa5f7

Browse files
committed
handling missing default values for defines
which were treated as None in copy_frame #430
1 parent d537f9c commit 77fa5f7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/canmatrix/copy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def copy_frame(frame_id, source_db, target_db):
177177
target_db.add_define_default(
178178
copy.deepcopy(attribute), copy.deepcopy(source_db.frame_defines[attribute].defaultValue))
179179
# only default value exists in source but is different to default value in target
180-
if attribute not in frame.attributes and \
180+
if attribute not in frame.attributes and frame.attribute(attribute, source_db) is not None and \
181181
frame.attribute(attribute, source_db) != frame.attribute(attribute, target_db):
182182
target_db.frame_by_id(frame.arbitration_id).add_attribute(attribute, frame.attribute(attribute, source_db))
183183
# update enum data types if needed:
@@ -202,7 +202,7 @@ def copy_frame(frame_id, source_db, target_db):
202202
target_db.signal_defines[attribute].values.append(copy.deepcopy(temp_attr))
203203
target_db.signal_defines[attribute].update()
204204
# only default value exists in source but is different to default value in target
205-
if attribute not in sig.attributes and \
205+
if attribute not in sig.attributes and sig.attribute(attribute, source_db) is not None and \
206206
sig.attribute(attribute, source_db) != sig.attribute(attribute, target_db):
207207
target_db.frame_by_id(frame.arbitration_id).signal_by_name(sig.name).add_attribute(attribute, sig.attribute(attribute, source_db))
208208

src/canmatrix/tests/test_copy.py

+4
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@ def test_copy_frame_default_attributes():
8787
source.add_define_default("some_attribute", "source_frame_default")
8888
source.add_signal_defines("some_signal_attribute", "STRING")
8989
source.add_define_default("some_signal_attribute", "source_sig_default")
90+
source.add_frame_defines("some_attribute_without_default", "STRING")
9091

9192
#test if default value only defined in source and copied to target
9293
target = canmatrix.canmatrix.CanMatrix()
94+
target.add_frame_defines("some_attribute_without_default", "STRING")
95+
target.add_define_default("some_attribute_without_default", "0")
9396
canmatrix.copy.copy_frame(frame1.arbitration_id, source, target)
9497
assert target.frames[0].attribute("some_attribute", target) == "source_frame_default"
9598
assert target.frames[0].signals[0].attribute("some_signal_attribute", target) == "source_sig_default"
99+
assert target.frames[0].attribute("some_attribute_without_default", target) == "0"
96100

97101
# test if define already exists, but has another default value:
98102
target2 = canmatrix.canmatrix.CanMatrix()

0 commit comments

Comments
 (0)