File: dlt_message_performance_test.py

package info (click to toggle)
python-dlt 2.18.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 452 kB
  • sloc: python: 3,449; makefile: 55
file content (39 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright (C) 2016. BMW Car IT GmbH. All rights reserved.
"""Basic unittests for DLT messages"""

import io
import unittest

from dlt.dlt import DLTFilter

from .utils import create_messages

stream_one = io.BytesIO(b"5\x00\x00 MGHS\xdd\xf6e\xca&\x01DA1\x00DC1\x00\x02\x0f\x00\x00\x00\x02\x00\x00\x00\x00")
stream_two = io.BytesIO(b"5\x00\x00 MGHS\xdd\xf6e\xca&\x01DA1\x00DC2\x00\x02\x0f\x00\x00\x00\x02\x00\x00\x00\x00")

LOOPS = 100000


class TestsDLTMessagePerf(unittest.TestCase):
    def setUp(self):
        self.msgs = [create_messages(stream_one) for i in range(int(LOOPS * 0.1))]
        self.msgs += [create_messages(stream_two) for i in range(int(LOOPS * 0.9))]

    def test_compare_dict(self):
        # with dict as other
        attrs = {"apid": "DA1", "ctid": "DC1"}
        for msg in self.msgs:
            msg.compare(other=attrs)

    def test_compare_filter(self):
        # with DLTFilter as other
        flt = DLTFilter()
        flt.add("DA1", "DC1")
        for msg in self.msgs:
            msg.compare(other=flt)

    def test_compare_mesage(self):
        # with dict as other
        other = create_messages(stream_one)
        for msg in self.msgs:
            msg.compare(other=other)