Coverage for battery/nubbin.py: 100%

12 statements  

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

1"""Defines a specilised Battery named Nubin Battery. 

2""" 

3 

4from datetime import datetime 

5from battery.base_battery import Battery 

6from utils.input_validator import validate_date 

7 

8 

9class NubbinBattery(Battery): 

10 """Creates NubbinBattery instances. 

11 

12 Inherits from the Battery class. 

13 

14 methods: 

15 needs_service: Determines if the battery should be serviced. 

16 """ 

17 def __init__(self, last_service_date: datetime, current_date: datetime): 

18 """Ïnitializes NubbinBattery objects.""" 

19 # validate input 

20 last_service_date = validate_date(last_service_date) 

21 current_date = validate_date(current_date) 

22 # initialize instance 

23 self.current_date = current_date 

24 self.last_service_date = last_service_date 

25 

26 

27 def needs_service(self) -> bool: 

28 """Determines if the NubbinBattery should be serviced. 

29 

30 Returns True if the battery needs service, False otherwise. 

31 

32 Usage: 

33 

34 battery = NubbinBattery(....) 

35 battery.needs_service() 

36 """ 

37 service_time_threshold = self.current_date - self.last_service_date 

38 return service_time_threshold.days >= 1460