Exemplo n.º 1
0
    def test_get_mileage_no_mileage_found(self):
        """
        If no mileage is found in the setup file, the odometer should start from 0
        """

        with patch("devices.odometer.SetupFile.get_value") as m_get_value:
            m_get_value.side_effect = AttributeError
            odo = Odometer()

        assert odo.get_mileage() == {"km": 0, "miles": 0}
Exemplo n.º 2
0
    def test_get_mileage(self, unit, value, expected_km, expected_miles):
        """
        Checks that the odometer reads the correct mileage after setting the value in the json setup file.
        """

        with patch("devices.odometer.SetupFile.get_value") as m_get_value:
            m_get_value.return_value = {"value": value, "unit": unit}
            odo = Odometer()

        assert odo.get_mileage() == {"km": expected_km, "miles": expected_miles}
Exemplo n.º 3
0
    def test_save_not_enough_distance_traveled(self):
        """
        The mileage should not increase if more than one km more is not reached
        """

        with freeze_time("00:00:00"):
            # setting the starting mileage
            with patch("devices.odometer.SetupFile.get_value") as get_value:
                get_value.return_value = {"value": 0}
                odo = Odometer()

        assert odo.get_mileage() == {"km": 0, "miles": 0}  # we are clean

        with freeze_time("00:00:30"):
            # after 30 secs we will notify the odometer that we have been going to 100km/h
            with patch("devices.odometer.SetupFile.update_key") as m_update_key:
                odo.save(100)
                # checking that we couldn't reach one km more so no update to the setup file is needed
                m_update_key.assert_not_called()

        # the mileage will remain the same
        assert odo.get_mileage() == {"km": 0, "miles": 0}
Exemplo n.º 4
0
    def test_save(self):
        """
        Checks that the mileage increases after been some time running to a certain speed.
        """

        with freeze_time("00:00:00"):
            # setting the starting mileage
            with patch("devices.odometer.SetupFile.get_value") as get_value:
                get_value.return_value = {"value": 0}
                odo = Odometer()

        assert odo.get_mileage() == {"km": 0, "miles": 0}  # we are clean

        with freeze_time("01:00:00"):
            # after an hour we will notify the odometer that we have been going to 100km/h
            with patch("devices.odometer.SetupFile.update_key") as m_update_key:
                odo.save(100)
                # checking that we tried to save the new mileage into the setup file
                m_update_key.assert_called_with("odo", {"value": 100})

        # after an hour we should be in 100km mileage
        assert odo.get_mileage() == {"km": 100, "miles": 62}
Exemplo n.º 5
0
 def _init_resources(self):
     self.time = Time()
     self.odo = Odometer()
     self.kpro = Kpro()
Exemplo n.º 6
0
from devices.kpro import Kpro
from devices.time import Time
from devices.odometer import Odometer

from mapper import Mapper

while True:
    try:
        run()
        break
    except:
        continue

kpro = Kpro()
time = Time()
odo = Odometer()
map = Mapper()

iat_unit = map.get_unit('iat')
ect_unit = map.get_unit('ect')
vss_unit = map.get_unit('vss')
o2_unit = map.get_unit('o2')
map_unit = map.get_unit('map')
an0_unit = map.get_unit('an0')
an0_formula = map.get_formula('an0')
an1_unit = map.get_unit('an1')
an1_formula = map.get_formula('an1')
an2_unit = map.get_unit('an2')
an2_formula = map.get_formula('an2')
an3_unit = map.get_unit('an3')
an3_formula = map.get_formula('an3')