fix toggling tests with mocking datetime.datetime.now()
This commit is contained in:
parent
643f98f121
commit
50bf465add
@ -6,6 +6,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import geopy
|
import geopy
|
||||||
from dse_shared_libs.daf import DAF
|
from dse_shared_libs.daf import DAF
|
||||||
|
from dse_shared_libs.mock.datetime import MyDate
|
||||||
from dse_shared_libs.target_velocity import TargetVelocity
|
from dse_shared_libs.target_velocity import TargetVelocity
|
||||||
from dse_shared_libs.traffic_light_color import TrafficLightColor
|
from dse_shared_libs.traffic_light_color import TrafficLightColor
|
||||||
|
|
||||||
@ -31,6 +32,9 @@ class TestVehicle(unittest.TestCase):
|
|||||||
self.v.last_update = self.timestamp
|
self.v.last_update = self.timestamp
|
||||||
self.v._driven_kms = 0
|
self.v._driven_kms = 0
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
def test_nce_prop(self):
|
def test_nce_prop(self):
|
||||||
with patch('time.sleep', return_value=None):
|
with patch('time.sleep', return_value=None):
|
||||||
# initially false
|
# initially false
|
||||||
@ -43,6 +47,10 @@ class TestVehicle(unittest.TestCase):
|
|||||||
self.assertEqual(self.v.nce, False)
|
self.assertEqual(self.v.nce, False)
|
||||||
|
|
||||||
def test_daf_prop(self):
|
def test_daf_prop(self):
|
||||||
|
with patch('datetime.datetime', MyDate):
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
|
datetime.datetime.set_timestamp(self.timestamp)
|
||||||
|
|
||||||
# test if daf object created properly
|
# test if daf object created properly
|
||||||
daf = DAF(vehicle_identification_number=self.vin,
|
daf = DAF(vehicle_identification_number=self.vin,
|
||||||
gps_location=self.starting_point,
|
gps_location=self.starting_point,
|
||||||
@ -52,6 +60,14 @@ class TestVehicle(unittest.TestCase):
|
|||||||
self.assertEqual(self.v.daf, daf)
|
self.assertEqual(self.v.daf, daf)
|
||||||
|
|
||||||
def test_current_location_prop(self):
|
def test_current_location_prop(self):
|
||||||
|
with patch('datetime.datetime', MyDate):
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
|
datetime.datetime.set_timestamp(self.timestamp)
|
||||||
|
|
||||||
|
# assert timestamp mocking worked
|
||||||
|
self.assertEqual(type(datetime.datetime), type(MyDate))
|
||||||
|
self.assertEqual(self.timestamp, datetime.datetime.now())
|
||||||
|
|
||||||
# initial position should be starting point
|
# initial position should be starting point
|
||||||
self.assertEqual(self.v.gps_location, self.starting_point)
|
self.assertEqual(self.v.gps_location, self.starting_point)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user