2026-06-25 20:16:16 +08:00
|
|
|
|
//go:build manual
|
|
|
|
|
|
|
2026-07-02 09:46:33 +08:00
|
|
|
|
package pdf
|
2026-06-25 20:16:16 +08:00
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"log/slog"
|
|
|
|
|
|
"os"
|
|
|
|
|
|
"path/filepath"
|
2026-07-10 11:58:32 +08:00
|
|
|
|
"ragflow/internal/common"
|
2026-06-25 20:16:16 +08:00
|
|
|
|
"testing"
|
|
|
|
|
|
|
2026-07-02 09:46:33 +08:00
|
|
|
|
"ragflow/internal/deepdoc/parser/pdf/tool"
|
2026-06-25 20:16:16 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
2026-07-10 11:58:32 +08:00
|
|
|
|
if common.GetEnv(common.EnvBatchLogLevel) == "debug" {
|
2026-06-25 20:16:16 +08:00
|
|
|
|
level = slog.LevelDebug
|
|
|
|
|
|
}
|
2026-07-10 11:58:32 +08:00
|
|
|
|
if common.GetEnv(common.EnvBatchLogLevel) == "warn" {
|
2026-06-25 20:16:16 +08:00
|
|
|
|
level = slog.LevelWarn
|
|
|
|
|
|
}
|
|
|
|
|
|
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})))
|
|
|
|
|
|
|
|
|
|
|
|
goVariant := "ocr"
|
2026-07-10 11:58:32 +08:00
|
|
|
|
if common.GetEnv(common.EnvBatchSkipOCR) == "1" {
|
2026-06-25 20:16:16 +08:00
|
|
|
|
goVariant = "noocr"
|
|
|
|
|
|
}
|
2026-07-10 11:58:32 +08:00
|
|
|
|
pyVariant := common.GetEnv(common.EnvPYOCRSuffix)
|
2026-06-25 20:16:16 +08:00
|
|
|
|
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).
|
2026-07-02 09:46:33 +08:00
|
|
|
|
goResults, err := tool.ReadGoTextMeta(goTextDir)
|
2026-06-25 20:16:16 +08:00
|
|
|
|
if err != nil || len(goResults) == 0 {
|
|
|
|
|
|
t.Fatalf("No Go text files in %s: %v", goTextDir, err)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Read Python text files' #@meta
|
2026-07-02 09:46:33 +08:00
|
|
|
|
pyResults, err := tool.ReadPythonTextMeta(pyTextDir)
|
2026-06-25 20:16:16 +08:00
|
|
|
|
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))
|
2026-07-02 09:46:33 +08:00
|
|
|
|
tool.CompareWithPython(t, goResults, pyResults, goTextDir, pyTextDir)
|
2026-06-25 20:16:16 +08:00
|
|
|
|
|
|
|
|
|
|
// Compare tables.
|
|
|
|
|
|
goTablesDir := filepath.Join("testdata", "output", "go", goVariant, "tables")
|
|
|
|
|
|
pyTablesDir2 := filepath.Join("testdata", "output", "py", pyVariant, "tables")
|
2026-07-02 09:46:33 +08:00
|
|
|
|
tool.CompareTablesWithPython(t, goTablesDir, pyTablesDir2)
|
2026-06-25 20:16:16 +08:00
|
|
|
|
// Compare DLA + TSR raw intermediates.
|
|
|
|
|
|
goDLADir := filepath.Join("testdata", "output", "go", goVariant, "dla")
|
|
|
|
|
|
pyDLADir := filepath.Join("testdata", "output", "py", pyVariant, "dla")
|
2026-07-02 09:46:33 +08:00
|
|
|
|
tool.CompareDLAWithPython(t, goDLADir, pyDLADir)
|
2026-06-25 20:16:16 +08:00
|
|
|
|
goTSRRawDir := filepath.Join("testdata", "output", "go", goVariant, "tsr_raw")
|
|
|
|
|
|
pyTSRRawDir := filepath.Join("testdata", "output", "py", pyVariant, "tsr_raw")
|
2026-07-02 09:46:33 +08:00
|
|
|
|
tool.CompareTSRRawWithPython(t, goTSRRawDir, pyTSRRawDir)
|
2026-06-25 20:16:16 +08:00
|
|
|
|
}
|