Files
ragflow/internal/deepdoc/parser/pdf/tool/compare_test.go
Jack 272645a27a fix(pdf): align DLA region handling with Python reference (#18295)
Aligns three Go DLA / PDF post-processing behaviors with the Python `deepdoc` reference so the Go PDF pipeline matches Python's DLA region / annotation semantics.
2026-08-17 14:33:44 +08:00

66 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build manual
package tool
import (
"log/slog"
"os"
"path/filepath"
"testing"
"ragflow/internal/common"
)
// TestBatchCompareWithPython compares Go output against Python reference
// across 4 dimensions (text, tables, DLA, TSR raw). It is read-only —
// no generation, no CGO/DeepDoc dependency. Use BATCH_SKIP_OCR=1 to
// compare the noocr variant; PY_OCR_SUFFIX to override the Python variant.
func TestBatchCompareWithPython(t *testing.T) {
level := slog.LevelInfo
if common.GetEnv(common.EnvBatchLogLevel) == "debug" {
level = slog.LevelDebug
}
if common.GetEnv(common.EnvBatchLogLevel) == "warn" {
level = slog.LevelWarn
}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})))
goVariant := "ocr"
if common.GetEnv(common.EnvBatchSkipOCR) == "1" {
goVariant = "noocr"
}
pyVariant := common.GetEnv(common.EnvPYOCRSuffix)
if pyVariant == "" {
pyVariant = goVariant
}
goTextDir := filepath.Join("testdata", "output", "go", goVariant, "text")
pyTextDir := filepath.Join("testdata", "output", "py", pyVariant, "text")
// Read Go text files' #@meta (no aggregate JSON dependency).
goResults, err := ReadGoTextMeta(goTextDir)
if err != nil || len(goResults) == 0 {
t.Fatalf("No Go text files in %s: %v", goTextDir, err)
}
// Read Python text files' #@meta
pyResults, err := ReadPythonTextMeta(pyTextDir)
if err != nil || len(pyResults) == 0 {
t.Fatalf("No Python text files in %s: %v", pyTextDir, err)
}
t.Logf("Comparing %d Go × %d Python", len(goResults), len(pyResults))
CompareWithPython(t, goResults, pyResults, goTextDir, pyTextDir)
// Compare tables.
goTablesDir := filepath.Join("testdata", "output", "go", goVariant, "tables")
pyTablesDir2 := filepath.Join("testdata", "output", "py", pyVariant, "tables")
CompareTablesWithPython(t, goTablesDir, pyTablesDir2)
// Compare DLA + TSR raw intermediates.
goDLADir := filepath.Join("testdata", "output", "go", goVariant, "dla")
pyDLADir := filepath.Join("testdata", "output", "py", pyVariant, "dla")
CompareDLAWithPython(t, goDLADir, pyDLADir)
goTSRRawDir := filepath.Join("testdata", "output", "go", goVariant, "tsr_raw")
pyTSRRawDir := filepath.Join("testdata", "output", "py", pyVariant, "tsr_raw")
CompareTSRRawWithPython(t, goTSRRawDir, pyTSRRawDir)
}