Beispiel #1
0
    def test_run_backend(self):
        with mock.patch("usb.core.find"), mock.patch(
                "devices.kpro.kpro.Kpro.__init__") as m___init__:
            # mocking kpro device since for tests is not available
            m___init__.return_value = None

            assert type(Backend.get()) == Backend
Beispiel #2
0
    def test_update(self):
        expected_data = {
            "bat": 0.0,
            "gear": "N",
            "iat": 0,
            "tps": 0,
            "ect": 0,
            "rpm": 0,
            "vss": 0,
            "o2": 0,
            "cam": 0,
            "mil": False,
            "fan": False,
            "bksw": False,
            "flr": False,
            "eth": 0,
            "scs": False,
            "fmw": "0.00",
            "map": 0,
            "an0": 104,
            "an1": 205.7905145,
            "an2": 205.7905145,
            "an3": 205.7905145,
            "an4": 205.7905145,
            "an5": 205.7905145,
            "an6": 205.7905145,
            "an7": 205.7905145,
            "time": "00:00:00",
            "odo": 0,
            "style": "day",
            "ver": "2.4.0",
        }

        with mock.patch("usb.core.find"), mock.patch(
                "usb.util.find_descriptor"), mock.patch(
                    "threading.Thread.start"), mock.patch(
                        "backend.backend.publish") as m_publish:
            backend = Backend.get()
            backend.update()
            m_publish.assert_called_with("data", expected_data)
import random
from time import sleep
from unittest import mock

from backend.backend import Backend

with mock.patch("usb.core.find"), mock.patch(
        "devices.kpro.kpro.Kpro.__init__") as m___init__:
    m___init__.return_value = None
    backend = Backend.get()
    backend.kpro.status = True
    backend.kpro.version = 4

    while True:
        backend.kpro.data0 = [random.randint(0, 255) for _ in range(38)]
        backend.kpro.data1 = [random.randint(0, 255) for _ in range(7)]
        backend.kpro.data3 = [random.randint(0, 255) for _ in range(100)]
        backend.kpro.data4 = [random.randint(0, 255) for _ in range(18)]
        backend.kpro.data5 = [random.randint(0, 255) for _ in range(20)]
        backend.update()
        sleep(0.1)  # TODO: not use sleep :(