Coverage for src/prosemark/domain/parser_result.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-09-30 23:09 +0000

1"""Parser result value objects for enhanced parsing. 

2 

3This module defines the ParserResult and ParsingMetadata value objects 

4for complete parsing results with structure and preserved content. 

5""" 

6 

7from dataclasses import dataclass 

8 

9from prosemark.domain.models import Binder 

10from prosemark.domain.preserved_text import PreservedText 

11 

12 

13@dataclass(frozen=True) 

14class ParsingMetadata: 

15 """Metadata about the parsing process and decisions made. 

16 

17 This value object tracks statistics about parsing decisions, 

18 validation results, and content analysis. 

19 """ 

20 

21 malformed_elements_count: int 

22 uuid_validation_failures: int 

23 original_line_count: int 

24 structural_line_count: int 

25 

26 def __post_init__(self) -> None: 

27 """Validate ParsingMetadata field constraints.""" 

28 if self.malformed_elements_count < 0: 

29 raise ValueError('malformed_elements_count must be non-negative') 

30 

31 if self.uuid_validation_failures < 0: 

32 raise ValueError('uuid_validation_failures must be non-negative') 

33 

34 if self.original_line_count < 0: 

35 raise ValueError('original_line_count must be non-negative') 

36 

37 if self.structural_line_count < 0: 

38 raise ValueError('structural_line_count must be non-negative') 

39 

40 if self.structural_line_count > self.original_line_count: 

41 raise ValueError('structural_line_count cannot exceed original_line_count') 

42 

43 

44@dataclass(frozen=True) 

45class ParserResult: 

46 """Complete parsing result with structure and preserved content. 

47 

48 This value object represents the complete result of enhanced parsing, 

49 including both the structural binder and all preserved text. 

50 """ 

51 

52 binder: Binder 

53 preserved_text: list[PreservedText] 

54 parsing_metadata: ParsingMetadata