diff --git a/components/i_feed/test_ifeed.py b/components/i_feed/test_ifeed.py index 45f5011..c195be7 100644 --- a/components/i_feed/test_ifeed.py +++ b/components/i_feed/test_ifeed.py @@ -6,6 +6,7 @@ from unittest.mock import patch import geopy 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.traffic_light_color import TrafficLightColor @@ -31,6 +32,9 @@ class TestVehicle(unittest.TestCase): self.v.last_update = self.timestamp self.v._driven_kms = 0 + def tearDown(self) -> None: + time.sleep(0.1) + def test_nce_prop(self): with patch('time.sleep', return_value=None): # initially false @@ -43,25 +47,37 @@ class TestVehicle(unittest.TestCase): self.assertEqual(self.v.nce, False) def test_daf_prop(self): - # test if daf object created properly - daf = DAF(vehicle_identification_number=self.vin, - gps_location=self.starting_point, - velocity=self.starting_velocity, - timestamp=self.timestamp, - near_crash_event=False) - self.assertEqual(self.v.daf, daf) + with patch('datetime.datetime', MyDate): + # noinspection PyUnresolvedReferences + datetime.datetime.set_timestamp(self.timestamp) + + # test if daf object created properly + daf = DAF(vehicle_identification_number=self.vin, + gps_location=self.starting_point, + velocity=self.starting_velocity, + timestamp=self.timestamp, + near_crash_event=False) + self.assertEqual(self.v.daf, daf) def test_current_location_prop(self): - # initial position should be starting point - self.assertEqual(self.v.gps_location, self.starting_point) + with patch('datetime.datetime', MyDate): + # noinspection PyUnresolvedReferences + datetime.datetime.set_timestamp(self.timestamp) - # lets say last time was about an hour ago - self.v.last_update = self.timestamp - datetime.timedelta(hours=1) + # assert timestamp mocking worked + self.assertEqual(type(datetime.datetime), type(MyDate)) + self.assertEqual(self.timestamp, datetime.datetime.now()) - # we drive "almost" directly north - loc = self.v.gps_location - self.assertEqual(round(loc.latitude, 2), 1.17) - self.assertEqual(round(loc.longitude, 2), 0.04) + # initial position should be starting point + self.assertEqual(self.v.gps_location, self.starting_point) + + # lets say last time was about an hour ago + self.v.last_update = self.timestamp - datetime.timedelta(hours=1) + + # we drive "almost" directly north + loc = self.v.gps_location + self.assertEqual(round(loc.latitude, 2), 1.17) + self.assertEqual(round(loc.longitude, 2), 0.04) def test_driven_kms_prop(self): # initial driven kms are 0