Coverage for compiler_admin / services / time.py: 70%

39 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 05:48 +0000

1import math 

2from dataclasses import dataclass, field 

3from datetime import date 

4from typing import MutableMapping 

5 

6 

7@dataclass 

8class TimeSummary: 

9 """Represents a summary of time entries.""" 

10 

11 earliest_date: date | None = None 

12 latest_date: date | None = None 

13 total_rows: int = 0 

14 total_hours: float = 0.0 

15 hours_per_project: MutableMapping[str, float] = field(default_factory=dict) 

16 hours_per_user_project: MutableMapping[str, MutableMapping[str, float]] = field(default_factory=dict) 

17 

18 def __eq__(self, other: object) -> bool: 

19 if not isinstance(other, TimeSummary): 19 ↛ 20line 19 didn't jump to line 20 because the condition on line 19 was never true

20 return NotImplemented 

21 

22 if self.earliest_date != other.earliest_date: 22 ↛ 23line 22 didn't jump to line 23 because the condition on line 22 was never true

23 return False 

24 if self.latest_date != other.latest_date: 24 ↛ 25line 24 didn't jump to line 25 because the condition on line 24 was never true

25 return False 

26 if self.total_rows != other.total_rows: 26 ↛ 27line 26 didn't jump to line 27 because the condition on line 26 was never true

27 return False 

28 if not math.isclose(self.total_hours, other.total_hours, rel_tol=1e-5): 

29 return False 

30 

31 if self.hours_per_project.keys() != other.hours_per_project.keys(): 31 ↛ 32line 31 didn't jump to line 32 because the condition on line 31 was never true

32 return False 

33 for key in self.hours_per_project: 

34 if not math.isclose(self.hours_per_project[key], other.hours_per_project[key], rel_tol=1e-5): 34 ↛ 35line 34 didn't jump to line 35 because the condition on line 34 was never true

35 return False 

36 

37 if self.hours_per_user_project.keys() != other.hours_per_user_project.keys(): 37 ↛ 38line 37 didn't jump to line 38 because the condition on line 37 was never true

38 return False 

39 for user, projects in self.hours_per_user_project.items(): 

40 if user not in other.hours_per_user_project: 40 ↛ 41line 40 didn't jump to line 41 because the condition on line 40 was never true

41 return False 

42 if projects.keys() != other.hours_per_user_project[user].keys(): 42 ↛ 43line 42 didn't jump to line 43 because the condition on line 42 was never true

43 return False 

44 for project, hours in projects.items(): 

45 if not math.isclose(hours, other.hours_per_user_project[user][project], rel_tol=1e-5): 45 ↛ 46line 45 didn't jump to line 46 because the condition on line 45 was never true

46 return False 

47 

48 return True