Coverage for src/galaxy_beep_frame/frame/header_type/base.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-31 04:18 +0200

1"""HeaderType class.""" 

2 

3from dataclasses import dataclass 

4from typing import TYPE_CHECKING 

5 

6from galaxy_beep_frame.exception.frame import ( 

7 AnswerNumberError, 

8 InvalidContinuationIndicatorError, 

9 MissingAnswerNumberError, 

10) 

11from galaxy_beep_frame.header_type import PossibleHeaderType 

12 

13from .continuation_indicator import ContinuationIndicator 

14 

15if TYPE_CHECKING: 

16 from galaxy_beep_frame.frame.state import FrameState 

17 

18 

19@dataclass(frozen=True) 

20class HeaderType: 

21 """Manage data about header type (MSG, RPY, etc.).""" 

22 

23 state: FrameState 

24 

25 @staticmethod 

26 def make( 

27 state: FrameState, 

28 continuation_indicator: ContinuationIndicator, 

29 possible_header_type: PossibleHeaderType, 

30 answer_number: int | None, 

31 ) -> HeaderType: 

32 """Build HeaderType depending on argument.""" 

33 from . import Answer, Error, Message, Null, Reply # noqa: PLC0415, I001 

34 

35 if possible_header_type is PossibleHeaderType.ANS: 

36 if answer_number is None: 

37 raise MissingAnswerNumberError 

38 return Answer( 

39 state=state, 

40 continuation_indicator=continuation_indicator, 

41 answer_number=answer_number, 

42 ) 

43 if answer_number is not None: 

44 raise AnswerNumberError(answer_number) 

45 

46 if possible_header_type is PossibleHeaderType.ERR: 

47 return Error( 

48 state=state, 

49 continuation_indicator=continuation_indicator, 

50 ) 

51 if possible_header_type is PossibleHeaderType.MSG: 

52 return Message( 

53 state=state, 

54 continuation_indicator=continuation_indicator, 

55 ) 

56 if possible_header_type is PossibleHeaderType.RPY: 

57 return Reply( 

58 state=state, 

59 continuation_indicator=continuation_indicator, 

60 ) 

61 

62 if continuation_indicator is ContinuationIndicator.INTERMEDIATE: 

63 raise InvalidContinuationIndicatorError( 

64 continuation_indicator, possible_header_type 

65 ) 

66 

67 return Null(state=state) 

68 

69 def build(self, size: int) -> bytes: # noqa: ARG002 

70 """Build the header of this Frame.""" 

71 

72 return NotImplemented