@@ -53,6 +53,7 @@ def test_create_comment_string():
53
53
test_string = canmatrix .formats .dbc .create_comment_string ("BO_" , "ident" , "some comment" , "utf8" , "utf8" , "" )
54
54
assert test_string == b'CM_ BO_ ident "some comment";\n '
55
55
56
+
56
57
def test_parse_comment_from_dbc ():
57
58
dbc = io .BytesIO (textwrap .dedent (u'''\
58
59
BO_ 1 someFrame: 1 someEcu
@@ -64,6 +65,7 @@ def test_parse_comment_from_dbc():
64
65
matrix = canmatrix .formats .dbc .load (dbc )
65
66
assert matrix .frames [0 ].signals [0 ].comment == "resistance setting (0-100%)"
66
67
68
+
67
69
def test_parse_multi_line_comment ():
68
70
dbc = io .BytesIO (textwrap .dedent (u'''\
69
71
BO_ 1 someFrame: 1 someEcu
@@ -240,6 +242,7 @@ def test_export_of_unknown_defines():
240
242
if line .startswith ("BA_ " ):
241
243
assert line .endswith ('";' )
242
244
245
+
243
246
def test_braces_in_attributes ():
244
247
dbc = io .BytesIO (textwrap .dedent (u'''\
245
248
BO_ 20 frameName: 1 someEcu
@@ -249,6 +252,7 @@ def test_braces_in_attributes():
249
252
''' ).encode ('utf-8' ))
250
253
matrix = canmatrix .formats .dbc .load (dbc , dbcImportEncoding = "utf8" )
251
254
255
+
252
256
def test_defines_with_spaces ():
253
257
dbc = io .BytesIO (textwrap .dedent (u'''\
254
258
BU_: someOtherEcu
@@ -276,6 +280,7 @@ def test_defines_with_spaces():
276
280
assert matrix .env_vars ["someEnvVar" ]["attributes" ]["some attrib" ] == '"some space"'
277
281
assert matrix .ecus [0 ].attributes ["Description X" ] == "Some Some Text"
278
282
283
+
279
284
def test_writing_complex_multiplex ():
280
285
db = canmatrix .CanMatrix ()
281
286
frame = canmatrix .Frame ("someFrame" )
@@ -307,6 +312,7 @@ def test_defines_with_special_cars():
307
312
matrix = canmatrix .formats .dbc .load (dbc , dbcImportEncoding = "utf8" )
308
313
assert matrix .frames [0 ].signals [0 ].attributes ["Accuracy" ] == "+/- 10.2 at 55.1%"
309
314
315
+
310
316
def test_j1939_frametype ():
311
317
dbc = io .BytesIO (textwrap .dedent (u'''\
312
318
BU_: someOtherEcu
@@ -346,6 +352,7 @@ def test_attributes_with_spaces_before_semicolumn():
346
352
assert matrix .frames [0 ].attributes ["someAttribute" ] == 'str'
347
353
assert matrix .frames [1 ].attribute ("someAttribute" , matrix ) == 'asd'
348
354
355
+
349
356
def test_cycle_time_handling ():
350
357
dbc = io .BytesIO (textwrap .dedent (u'''\
351
358
BO_ 17 Frame_1: 8 Vector__XXX
@@ -381,6 +388,7 @@ def test_cycle_time_handling():
381
388
outdbc = io .BytesIO ()
382
389
canmatrix .formats .dump ({"aa" :matrix }, outdbc , "kcd" )
383
390
391
+
384
392
def test_keep_cycle_time_defines ():
385
393
dbc = io .BytesIO (textwrap .dedent (u'''\
386
394
BO_ 17 Frame_1: 8 Vector__XXX
@@ -396,6 +404,7 @@ def test_keep_cycle_time_defines():
396
404
assert 'BA_DEF_ BO_ "GenMsgCycleTime" INT 0 50000' in outdbc .getvalue ().decode ('utf8' )
397
405
assert 'BA_DEF_DEF_ "GenMsgCycleTime" 0' in outdbc .getvalue ().decode ('utf8' )
398
406
407
+
399
408
def test_unique_signal_names ():
400
409
db = canmatrix .CanMatrix ()
401
410
frame = canmatrix .Frame ("some Frame" )
@@ -413,6 +422,7 @@ def test_unique_signal_names():
413
422
assert "signal_name1" not in outdbc .getvalue ().decode ('utf8' )
414
423
assert "signal_name" in outdbc .getvalue ().decode ('utf8' )
415
424
425
+
416
426
def test_signal_inital_value ():
417
427
dbc = io .BytesIO (textwrap .dedent (u'''\
418
428
BO_ 17 Frame_1: 8 Vector__XXX
@@ -480,6 +490,7 @@ def test_missing_space():
480
490
matrix = canmatrix .formats .dbc .load (dbc , dbcImportEncoding = "utf8" )
481
491
assert matrix .frames [0 ].signals [0 ].name == "sig1"
482
492
493
+
483
494
def test_escaped_quotes ():
484
495
dbc = io .BytesIO (textwrap .dedent (r'''
485
496
BO_ 17 Frame_1: 8 Vector__XXX
@@ -518,6 +529,37 @@ def test_without_ecu():
518
529
matrix .frames [0 ].signals [0 ].name == "A_B_C_D_E"
519
530
520
531
532
+ def test_default_initial_value ():
533
+ dbc = io .BytesIO (textwrap .dedent (u'''\
534
+ BO_ 560 ECU1_Message: 1 ECU1
535
+ SG_ ECU2_Signal : 0|8@0+ (1,-5) [-2|250] "g" ECU2
536
+
537
+ BA_DEF_ SG_ "GenSigStartValue" FLOAT 0.0 100.0;
538
+
539
+ BA_DEF_DEF_ "GenSigStartValue" 10.0;
540
+ ''' ).encode ('utf-8' ))
541
+
542
+ matrix = canmatrix .formats .dbc .load (dbc , dbcImportEncoding = "utf8" )
543
+ assert matrix .frames [0 ].signals [0 ].initial_value == 10
544
+ # outdbc = io.BytesIO()
545
+ # canmatrix.formats.dump(matrix, outdbc, "dbc")
546
+
547
+
548
+ def test_no_initial_value ():
549
+ dbc = io .BytesIO (textwrap .dedent (u'''\
550
+ BO_ 560 ECU1_Message: 1 ECU1
551
+ SG_ ECU2_Signal : 0|8@0+ (1,-5) [-2|250] "g" ECU2
552
+
553
+ BA_DEF_ SG_ "GenSigStartValue" FLOAT 0.0 100.0;
554
+ ''' ).encode ('utf-8' ))
555
+
556
+ matrix = canmatrix .formats .dbc .load (dbc , dbcImportEncoding = "utf8" )
557
+ outdbc = io .BytesIO ()
558
+ canmatrix .formats .dump (matrix , outdbc , "dbc" )
559
+ assert 'BA_ "GenSigStartValue" SG_ 560 ECU2_Signal 5;' in outdbc .getvalue ().decode ('utf8' )
560
+ # assert matrix.frames[0].signals[0].initial_value == 10
561
+
562
+
521
563
def test_int_attribute_zero ():
522
564
db = canmatrix .CanMatrix ()
523
565
frame = canmatrix .Frame ("some Frame" )
0 commit comments