Coverage for battery/spindler.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-09 21:08 +0000

1"""This module defines a specilised Battery named Spindler Battery. 

2""" 

3 

4from datetime import datetime 

5from battery.base_battery import Battery 

6from utils.input_validator import validate_date 

7 

8 

9class SpindlerBattery(Battery): 

10 """Creates SpindlerBattery instances. 

11 

12 Inherits from the Battery class. 

13 

14 methods: 

15 needs_serviced: Determines if the battery should be serviced. 

16 """ 

17 def __init__(self, last_service_date: datetime, 

18 current_date: datetime): 

19 """Ïnitializes SpindlerBattery objects.""" 

20 # validate input 

21 current_date = validate_date(current_date) 

22 self.current_date = current_date 

23 self.last_service_date = last_service_date 

24 

25 

26 def needs_service(self) -> bool: 

27 """Determines if the Spindler Battery should be serviced. 

28 

29 Returns True if it's been three years(1095 days) since the last service date 

30 and False if otherwise. 

31 

32 Usage: 

33 battery = SpindlerBattery(....) 

34 battery.needs_service() 

35 """ 

36 service_time_threshold = self.current_date - self.last_service_date 

37 return service_time_threshold.days >= 1095