Coverage for functions \ flipdare \ result \ output_result.py: 79%

48 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13 

14from dataclasses import dataclass 

15from typing import Any, Self 

16from flipdare.constants import NO_DOC_ID 

17from flipdare.error.app_error_protocol import AppErrorProtocol 

18from flipdare.generated.shared.app_error_code import AppErrorCode 

19from flipdare.generated.shared.backend.app_job_type import AppJobType 

20from flipdare.result.outcome import Outcome 

21from flipdare.generated.shared.firestore_collections import FirestoreCollections 

22 

23 

24@dataclass(kw_only=True, slots=True) 

25class OutputResult: 

26 outcome: Outcome 

27 message: str 

28 duration: int 

29 error_code: AppErrorProtocol | None = None 

30 doc_id: str = NO_DOC_ID 

31 job_type: AppJobType | None = None 

32 collection: FirestoreCollections | None = None 

33 

34 @classmethod 

35 def error( 

36 cls, 

37 *, 

38 error_code: AppErrorProtocol, 

39 message: str, 

40 duration: int, 

41 doc_id: str = NO_DOC_ID, 

42 **kwargs: Any, 

43 ) -> Self: 

44 return cls( 

45 outcome=Outcome.ERROR, 

46 message=message, 

47 duration=duration, 

48 error_code=error_code, 

49 doc_id=doc_id, 

50 **kwargs, 

51 ) 

52 

53 @classmethod 

54 def partial( 

55 cls, 

56 *, 

57 error_code: AppErrorCode, 

58 message: str, 

59 duration: int, 

60 doc_id: str = NO_DOC_ID, 

61 **kwargs: Any, 

62 ) -> Self: 

63 return cls( 

64 outcome=Outcome.WARNING, 

65 message=message, 

66 duration=duration, 

67 error_code=error_code, 

68 doc_id=doc_id, 

69 **kwargs, 

70 ) 

71 

72 @classmethod 

73 def ok( 

74 cls, 

75 *, 

76 duration: int = -1, 

77 doc_id: str = NO_DOC_ID, 

78 message: str, 

79 **kwargs: Any, 

80 ) -> Self: 

81 return cls( 

82 outcome=Outcome.OK, 

83 message=message, 

84 duration=duration, 

85 error_code=None, 

86 doc_id=doc_id, 

87 **kwargs, 

88 ) 

89 

90 # --------------------------------------------------------------------------------------------- 

91 # Properties 

92 # --------------------------------------------------------------------------------------------- 

93 

94 @property 

95 def is_ok(self) -> bool: 

96 return self.outcome == Outcome.OK 

97 

98 @property 

99 def is_error(self) -> bool: 

100 return self.outcome == Outcome.ERROR 

101 

102 @property 

103 def is_partial(self) -> bool: 

104 return self.outcome == Outcome.WARNING 

105 

106 @property 

107 def is_skipped(self) -> bool: 

108 return self.outcome == Outcome.SKIPPED 

109 

110 # --------------------------------------------------------------------------------------------- 

111 # state 

112 # --------------------------------------------------------------------------------------------- 

113 

114 def set_ok( 

115 self, 

116 message: str, 

117 doc_id: str | None = None, 

118 ) -> None: 

119 self.outcome = Outcome.OK 

120 self.error_code = None 

121 self.message = message 

122 if doc_id is not None: 

123 self.doc_id = doc_id 

124 

125 def set_error( 

126 self, 

127 error_code: AppErrorCode, 

128 message: str, 

129 ) -> None: 

130 self.outcome = Outcome.ERROR 

131 self.error_code = error_code 

132 self.message = message