Skip to content

Commit

Permalink
Merge pull request #183 from otiai10/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
otiai10 authored Dec 16, 2019
2 parents cca9300 + c3cc469 commit 65ae105
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 53 deletions.
31 changes: 28 additions & 3 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ import (
"image"
"io/ioutil"
"os"
"strings"
"testing"

. "github.com/otiai10/mint"
)

func TestMain(m *testing.M) {
beforeTest()
code := m.Run()
os.Exit(code)
}

func beforeTest() {
if strings.HasPrefix(Version(), "4.") {
os.Setenv("TESS_LSTM_DISABLED", "1")
}
switch os.Getenv("TESTCASE") {
case "archlinux", "centos", "fedora":
os.Setenv("TESS_BOX_DISABLED", "1")
}
}

func TestVersion(t *testing.T) {
version := Version()
Expect(t, version).Match("[0-9]{1}.[0-9]{1,2}(.[0-9a-z_-]*)?")
Expand Down Expand Up @@ -194,6 +206,11 @@ func TestClient_ConfigFilePath(t *testing.T) {
}

func TestClientBoundingBox(t *testing.T) {

if os.Getenv("TESS_BOX_DISABLED") == "1" {
t.Skip()
}

client := NewClient()
defer client.Close()
client.SetImage("./test/data/001-helloworld.png")
Expand All @@ -220,6 +237,11 @@ func TestClientBoundingBox(t *testing.T) {
}

func TestClient_HTML(t *testing.T) {

if os.Getenv("TESS_BOX_DISABLED") == "1" {
t.Skip()
}

client := NewClient()
defer client.Close()
client.SetImage("./test/data/001-helloworld.png")
Expand All @@ -230,6 +252,8 @@ func TestClient_HTML(t *testing.T) {
page := new(Page)
err = xml.Unmarshal([]byte(out), page)
Expect(t, err).ToBe(nil)
Expect(t, len(page.Content.Par.Lines)).ToBe(1)
Expect(t, len(page.Content.Par.Lines[0].Words)).ToBe(2)
Expect(t, page.Content.Par.Lines[0].Words[0].Characters).ToBe("Hello,")
Expect(t, page.Content.Par.Lines[0].Words[1].Characters).ToBe("World!")

Expand All @@ -253,7 +277,8 @@ func TestClient_HTML(t *testing.T) {
}

func TestGetAvailableLangs(t *testing.T) {
langs, err := GetAvailableLanguages()
Expect(t, err).ToBe(nil)
Expect(t, len(langs)).ToBe(1) // eng only
t.Skip("TODO")
// langs, err := GetAvailableLanguages()
// Expect(t, err).ToBe(nil)
// Expect(t, len(langs)).ToBe(1) // eng only
}
1 change: 1 addition & 0 deletions tessbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int Init(TessBaseAPI a, char* tessdataprefix, char* languages, char* configfilep
// {{{ Restore default stderr
(void)freopen("/dev/null", "a", stderr);
dup2(original_stderr, STDERR_FILENO);
close(original_stderr);
setbuf(stderr, NULL);
// }}}

Expand Down
4 changes: 2 additions & 2 deletions test/runtime
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e
set -o pipefail

PROJDIR=$(dirname $(cd $(dirname ${0}); pwd -P))
PROJDIR=$(dirname "$(cd "$(dirname "${0}")"; pwd -P)")

# {{{ Help message
function help() {
Expand Down Expand Up @@ -105,7 +105,7 @@ function test_docker_runtimes() {
docker pull gosseract/test:${testcase} | sed "s/^/│ /"
fi
echo "│ [Docker] Running tests..."
docker run -i -t --rm gosseract/test:${testcase} | sed "s/^/│ [${testcase}] /"
docker run -i -t -e "TESTCASE=${testcase}" --rm gosseract/test:${testcase} | sed "s/^/│ [${testcase}] /"
if [ -n "${PUSH}" ]; then
echo "│ [Docker] Pushing the image..."
docker push gosseract/test:${testcase} | sed "s/^/│ /"
Expand Down
116 changes: 68 additions & 48 deletions test/runtimes/centos.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,77 @@
FROM centos:latest

RUN yum update -y
RUN yum install -y yum-plugin-ovl epel-release
RUN yum install -y \
golang \
make \
gcc-c++ \
wget \
git \
tar \
autoconf \
automake \
libtool \
libjpeg-devel \
libpng-devel \
libtiff-devel \
libicu-devel \
libpango1.0-dev \
libcairo-dev \
zlib-devel

ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
# RUN yum update -y
RUN dnf install -y 'dnf-command(config-manager)' \
&& dnf config-manager --add-repo \
https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_8/ \
&& rpm --import \
https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key \
&& dnf install -y \
tesseract-devel \
leptonica-devel \
golang \
git \
gcc-c++
# && dnf install -y tesseract-langpack-deu
# RUN /usr/bin/dnf install -y 'dnf-command(config-manager)'
# RUN dnf config-manager --add-repo https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_8/
# RUN yum install -y yum-plugin-ovl epel-release
# RUN yum install -y \
# golang \
# make \
# gcc-c++ \
# wget \
# git \
# tar \
# autoconf \
# automake \
# libtool \
# libjpeg-devel \
# libpng-devel \
# libtiff-devel \
# libicu-devel \
# libpango1.0-dev \
# libcairo-dev \
# zlib-devel

# RUN dnf install -y golang git gcc-c++

# ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
# RUN ls -la /usr/local/lib

# Leptonica
RUN mkdir -p /tmp/leptonica \
&& wget -nv https://github.com/DanBloomberg/leptonica/archive/1.74.4.tar.gz \
&& tar -xzf 1.74.4.tar.gz -C /tmp/leptonica \
&& mv /tmp/leptonica/* /leptonica && cd /leptonica && mkdir m4 \
&& autoreconf -i \
&& chmod a+x ./autobuild && ./autobuild \
&& chmod a+x ./configure && ./configure \
&& make && make install

ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
ENV LIBLEPT_HEADERSDIR=/usr/local/include

# Tesseract
RUN mkdir -p /tmp/tesseract \
&& wget -nv https://github.com/tesseract-ocr/tesseract/archive/3.05.02.tar.gz \
&& tar -xzf 3.05.02.tar.gz -C /tmp/tesseract \
&& mv /tmp/tesseract/* /tesseract && cd /tesseract \
&& ./autogen.sh && ./configure \
&& make && make install

ENV TESSDATA_PREFIX=/usr/share/tesseract
RUN mkdir -p ${TESSDATA_PREFIX}/tessdata
RUN wget -nv https://github.com/tesseract-ocr/tessdata/raw/3.04.00/eng.traineddata \
-O ${TESSDATA_PREFIX}/tessdata/eng.traineddata
# RUN mkdir -p /tmp/leptonica \
# && wget -nv https://github.com/DanBloomberg/leptonica/archive/1.74.4.tar.gz \
# && tar -xzf 1.74.4.tar.gz -C /tmp/leptonica \
# && mv /tmp/leptonica/* /leptonica && cd /leptonica && mkdir m4 \
# && autoreconf -i \
# && chmod a+x ./autobuild && ./autobuild \
# && chmod a+x ./configure && ./configure \
# && make && make install

# ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# ENV LIBLEPT_HEADERSDIR=/usr/local/include

# # Tesseract
# RUN mkdir -p /tmp/tesseract \
# && wget -nv https://github.com/tesseract-ocr/tesseract/archive/3.05.02.tar.gz \
# && tar -xzf 3.05.02.tar.gz -C /tmp/tesseract \
# && mv /tmp/tesseract/* /tesseract && cd /tesseract \
# && ./autogen.sh && ./configure \
# && make && make install

# ENV TESSDATA_PREFIX=/usr/share/tesseract
# RUN mkdir -p ${TESSDATA_PREFIX}/tessdata
# RUN wget -nv https://github.com/tesseract-ocr/tessdata/raw/3.04.00/eng.traineddata \
# -O ${TESSDATA_PREFIX}/tessdata/eng.traineddata

ENV GOPATH=/root/go
# Dependencies for tests
RUN go get github.com/otiai10/mint golang.org/x/net/html
# Mount source code of gosseract project
ENV GO111MODULE=on
# # Dependencies for tests
# RUN go get github.com/otiai10/mint golang.org/x/net/html
# # Mount source code of gosseract project
ADD . ${GOPATH}/src/github.com/otiai10/gosseract
WORKDIR ${GOPATH}/src/github.com/otiai10/gosseract
RUN go get -t -v ./...

CMD ["go", "test", "-v", "github.com/otiai10/gosseract"]
2 changes: 2 additions & 0 deletions test/runtimes/freebsd.Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Vagrant.configure("2") do |config|

config.vm.provision :shell, :inline => '
pkg install -y --quiet tesseract git go
mv /usr/local/share/tessdata/*.traineddata /tmp
mv /tmp/eng.traineddata /usr/local/share/tessdata/
export GOPATH=~/go
go get -t github.com/otiai10/gosseract
'
Expand Down

0 comments on commit 65ae105

Please sign in to comment.