feat: Update testing documentation and introduce comprehensive report for IPSExtractor campaign. Add sections for executive summary, objectives, environment details, and methodology. Enhance README with compilation instructions and data sources for metrics analysis.
This commit is contained in:
+98
@@ -0,0 +1,98 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pys/pdf-count/internal/domain"
|
||||
"github.com/pys/pdf-count/internal/ocr"
|
||||
)
|
||||
|
||||
func testPDFDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
if d := os.Getenv("COUNT_TEST_PDF_DIR"); d != "" {
|
||||
return d
|
||||
}
|
||||
// services/services-count-facturas-medicas-serving → docs/plan_pruebas/data
|
||||
candidates := []string{
|
||||
filepath.Join("..", "..", "..", "..", "docs", "plan_pruebas", "data"),
|
||||
filepath.Join("..", "..", "..", "docs", "plan_pruebas", "data"),
|
||||
}
|
||||
for _, c := range candidates {
|
||||
abs, err := filepath.Abs(c)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if st, err := os.Stat(abs); err == nil && st.IsDir() {
|
||||
return abs
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func listFixturePDFs(t *testing.T, dir string) []string {
|
||||
t.Helper()
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("read pdf dir: %v", err)
|
||||
}
|
||||
var files []string
|
||||
for _, e := range entries {
|
||||
if e.IsDir() {
|
||||
continue
|
||||
}
|
||||
name := e.Name()
|
||||
if strings.EqualFold(filepath.Ext(name), ".pdf") {
|
||||
files = append(files, filepath.Join(dir, name))
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
func TestProcessPDFTimingFixtures(t *testing.T) {
|
||||
dir := testPDFDir(t)
|
||||
if dir == "" {
|
||||
t.Skip("PDF fixtures not found; set COUNT_TEST_PDF_DIR")
|
||||
}
|
||||
pdfs := listFixturePDFs(t, dir)
|
||||
if len(pdfs) == 0 {
|
||||
t.Skip("no PDF files in " + dir)
|
||||
}
|
||||
|
||||
engine, err := ocr.NewEngine("spa", 1)
|
||||
if err != nil {
|
||||
t.Skipf("tesseract not available: %v", err)
|
||||
}
|
||||
defer engine.Close()
|
||||
|
||||
proc := NewProcessor(nil, engine, Options{
|
||||
DPI: 200, // faster than 300 for timing smoke
|
||||
DBSCANEps: 10,
|
||||
DBSCANMinSamples: 1,
|
||||
LogPipelineTiming: true,
|
||||
})
|
||||
|
||||
t.Logf("pdf_dir=%s files=%d", dir, len(pdfs))
|
||||
t.Logf("%-28s %8s %8s %8s %8s %8s %6s %s",
|
||||
"file", "render", "ocr", "cluster", "infer", "total", "count", "status")
|
||||
|
||||
for _, path := range pdfs {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", path, err)
|
||||
}
|
||||
name := filepath.Base(path)
|
||||
res := proc.ProcessPDF(name, data)
|
||||
t.Logf("%-28s %6dms %6dms %6dms %6dms %6dms %6d %s",
|
||||
name, res.RenderMs, res.OCRMs, res.ClusterMs, res.InferMs, res.TotalMs, res.ServiceCount, res.Status)
|
||||
if res.Status == domain.StatusError {
|
||||
t.Errorf("%s failed: %s", name, res.Error)
|
||||
continue
|
||||
}
|
||||
if res.TotalMs <= 0 {
|
||||
t.Errorf("%s: TotalMs should be > 0", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user