-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpool_test.go
68 lines (60 loc) · 1.58 KB
/
pool_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package gogosseract_test
import (
"bytes"
"context"
"io"
"testing"
"time"
"github.com/danlock/gogosseract"
"github.com/danlock/pkg/test"
)
func TestPool(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
_, err := gogosseract.NewPool(ctx, 5, gogosseract.PoolConfig{
Config: gogosseract.Config{
TrainingData: bytes.NewBuffer([]byte{}),
},
})
if err == nil {
t.Fatalf("gogosseract.NewPool should have failed")
}
pool, err := gogosseract.NewPool(ctx, 5, gogosseract.PoolConfig{
Config: gogosseract.Config{
TrainingData: bytes.NewBuffer(engTrainedData),
},
})
test.FailOnError(t, err)
defer pool.Close()
images := [...]io.Reader{
bytes.NewBuffer(logoImg), bytes.NewBuffer(docsImg),
bytes.NewBuffer(logoImg), bytes.NewBuffer(docsImg),
bytes.NewBuffer(logoImg), bytes.NewBuffer(docsImg),
bytes.NewBuffer(logoImg), bytes.NewBuffer(docsImg),
bytes.NewBuffer(logoImg), bytes.NewBuffer(docsImg),
}
textChan := make(chan string, len(images))
for _, img := range images {
go func(img io.Reader) {
text, err := pool.ParseImage(ctx, img, gogosseract.ParseImageOptions{})
if err != nil {
panic(err)
}
textChan <- text
}(img)
}
for range images {
select {
case <-ctx.Done():
t.Fatal("timed out waiting for Pool.ParseImage")
case r := <-textChan:
if r != logoText && r != docsText {
t.Fatalf("Pool.ParseImage returned unexpected text %s", r)
}
}
}
_, err = pool.ParseImage(ctx, nil, gogosseract.ParseImageOptions{})
if err == nil {
t.Fatalf("pool.ParseImage didn't return error")
}
}