Пример #1
0
 def test_encode_canmatrix(self):
     db_path = os.path.join(os.path.dirname(__file__), "..", "test",
                            "test.dbc")
     for bus in formats.loadp(db_path).values():
         test_frame1 = 0x123
         data = {
             'Signal': 2,
             'someTestSignal': 101,
         }
         data_bytes = tuple(bytearray(bus.encode(test_frame1, data)))
         assert data_bytes == (0, 0x28, 0x04, 0, 0, 0, 0, 0)
Пример #2
0
 def test_import_export_additional_frame_info(self):
     db_path = os.path.join(
         os.path.dirname(__file__), "..", "test", "test.dbc")
     dbs = formats.loadp(db_path)
     tmp_dir = tempfile.mkdtemp()
     for extension in ['csv', 'json']:
         out_file_name = tmp_dir + "/output." + extension
         formats.dumpp(dbs, out_file_name, additionalFrameAttributes="UserFrameAttr")
         with open(out_file_name, "r") as file:
             data = file.read()
         self.assertIn("UserFrameAttr", data)
Пример #3
0
 def test_encode_canmatrix(self):
     db_path = os.path.join(
         os.path.dirname(__file__), "..", "test", "test.dbc")
     for bus in formats.loadp(db_path).values():
         test_frame1 = 0x123
         data = {
             'Signal': 2,
             'someTestSignal': 101,
         }
         data_bytes = tuple(bytearray(bus.encode(test_frame1, data)))
         assert data_bytes == (0, 0x28, 0x04, 0, 0, 0, 0, 0)
Пример #4
0
 def test_import_export_additional_frame_info(self):
     db_path = os.path.join(os.path.dirname(__file__), "..", "test",
                            "test.dbc")
     dbs = formats.loadp(db_path)
     tmp_dir = tempfile.mkdtemp()
     for extension in ['csv', 'json']:
         out_file_name = tmp_dir + "/output." + extension
         formats.dumpp(dbs,
                       out_file_name,
                       additionalFrameAttributes="UserFrameAttr")
         with open(out_file_name, "r") as file:
             data = file.read()
         self.assertIn("UserFrameAttr", data)
Пример #5
0
    def test_encode_decode_signal_value_choice_str(self):
        db_path = os.path.join(os.path.dirname(__file__), "..", "test",
                               "test.dbc")
        for bus in formats.loadp(db_path).values():
            test_frame1 = 0x123

            data = {'Signal': 'two'}
            data_bytes = tuple(bytearray(bus.encode(test_frame1, data)))

            decoded = bus.decode(test_frame1, data_bytes, True)

            for k, v in data.items():
                assert str(decoded[k]) == v
Пример #6
0
    def test_encode_decode_signal_value(self):
        db_path = os.path.join(os.path.dirname(__file__), "..", "test",
                               "test.dbc")
        for bus in formats.loadp(db_path).values():
            test_frame1 = 0x123

            data = {
                'Signal': 2,
                'someTestSignal': 101,
            }
            data_bytes = tuple(bytearray(bus.encode(test_frame1, data)))
            decoded = bus.decode(test_frame1, data_bytes, False)

            for k, v in data.items():
                assert decoded[k] == v
Пример #7
0
    def test_encode_decode_signal_value_choice_str(self):
        db_path = os.path.join(
            os.path.dirname(__file__), "..", "test", "test.dbc")
        for bus in formats.loadp(db_path).values():
            test_frame1 = 0x123

            data = {
                'Signal': 'two'
            }
            data_bytes = tuple(bytearray(bus.encode(test_frame1, data)))

            decoded = bus.decode(test_frame1, data_bytes, True)

            for k, v in data.items():
                assert str(decoded[k]) == v
Пример #8
0
    def test_encode_decode_signal_value(self):
        db_path = os.path.join(
            os.path.dirname(__file__), "..", "test", "test.dbc")
        for bus in formats.loadp(db_path).values():
            test_frame1 = 0x123

            data = {
                'Signal': 2,
                'someTestSignal': 101,
            }
            data_bytes = tuple(bytearray(bus.encode(test_frame1, data)))
            decoded = bus.decode(test_frame1, data_bytes, False)

            for k, v in data.items():
                assert decoded[k] == v