2026-07-02 09:46:33 +08:00
|
|
|
package pdf
|
2026-06-25 20:16:16 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"image"
|
2026-06-29 18:46:41 +08:00
|
|
|
pdf "ragflow/internal/deepdoc/parser/pdf/type"
|
2026-06-25 20:16:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// MockDocAnalyzer returns predefined data for unit tests.
|
|
|
|
|
// Set an Err field to non-nil to exercise the corresponding error path.
|
|
|
|
|
type MockDocAnalyzer struct {
|
2026-06-29 18:46:41 +08:00
|
|
|
DLARegions []pdf.DLARegion
|
|
|
|
|
TSRCells []pdf.TSRCell
|
|
|
|
|
OCRBoxes []pdf.OCRBox
|
|
|
|
|
OCRTexts []pdf.OCRText
|
2026-06-25 20:16:16 +08:00
|
|
|
// Per-method error injection for testing failure paths.
|
|
|
|
|
DLAErr error
|
|
|
|
|
TSRErr error
|
|
|
|
|
OCRDetectErr error
|
|
|
|
|
OCRRecognizeErr error
|
|
|
|
|
|
|
|
|
|
Healthy bool
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-29 18:46:41 +08:00
|
|
|
func (m *MockDocAnalyzer) DLA(_ context.Context, _ image.Image) ([]pdf.DLARegion, error) {
|
2026-06-25 20:16:16 +08:00
|
|
|
if m.DLAErr != nil {
|
|
|
|
|
return nil, m.DLAErr
|
|
|
|
|
}
|
|
|
|
|
return m.DLARegions, nil
|
|
|
|
|
}
|
2026-06-29 18:46:41 +08:00
|
|
|
func (m *MockDocAnalyzer) TSR(_ context.Context, _ image.Image) ([]pdf.TSRCell, error) {
|
2026-06-25 20:16:16 +08:00
|
|
|
if m.TSRErr != nil {
|
|
|
|
|
return nil, m.TSRErr
|
|
|
|
|
}
|
|
|
|
|
return m.TSRCells, nil
|
|
|
|
|
}
|
2026-06-29 18:46:41 +08:00
|
|
|
func (m *MockDocAnalyzer) OCRDetect(_ context.Context, _ image.Image) ([]pdf.OCRBox, error) {
|
2026-06-25 20:16:16 +08:00
|
|
|
if m.OCRDetectErr != nil {
|
|
|
|
|
return nil, m.OCRDetectErr
|
|
|
|
|
}
|
|
|
|
|
return m.OCRBoxes, nil
|
|
|
|
|
}
|
2026-06-29 18:46:41 +08:00
|
|
|
func (m *MockDocAnalyzer) OCRRecognize(_ context.Context, _ image.Image) ([]pdf.OCRText, error) {
|
2026-06-25 20:16:16 +08:00
|
|
|
if m.OCRRecognizeErr != nil {
|
|
|
|
|
return nil, m.OCRRecognizeErr
|
|
|
|
|
}
|
|
|
|
|
return m.OCRTexts, nil
|
|
|
|
|
}
|
2026-06-29 18:46:41 +08:00
|
|
|
func (m *MockDocAnalyzer) Health() bool { return m.Healthy }
|