mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-07-06 17:39:57 +02:00
do an actual test run
This commit is contained in:
parent
3905203294
commit
4e1956df5e
5 changed files with 82 additions and 1 deletions
2
.github/workflows/test-eynollah.yml
vendored
2
.github/workflows/test-eynollah.yml
vendored
|
@ -32,4 +32,4 @@ jobs:
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install .
|
pip install .
|
||||||
- name: Test with pytest
|
- name: Test with pytest
|
||||||
run: echo success # make test
|
run: make test
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -1,3 +1,6 @@
|
||||||
|
EYNOLLAH_MODELS ?= $(PWD)/models_eynollah
|
||||||
|
export EYNOLLAH_MODELS
|
||||||
|
|
||||||
# BEGIN-EVAL makefile-parser --make-help Makefile
|
# BEGIN-EVAL makefile-parser --make-help Makefile
|
||||||
|
|
||||||
help:
|
help:
|
||||||
|
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
54
tests/base.py
Normal file
54
tests/base.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
# pylint: disable=unused-import
|
||||||
|
|
||||||
|
from os.path import dirname, realpath
|
||||||
|
from os import chdir
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
import io
|
||||||
|
import collections
|
||||||
|
from unittest import TestCase as VanillaTestCase, skip, main as unittests_main
|
||||||
|
import pytest
|
||||||
|
from ocrd_utils import disableLogging, initLogging
|
||||||
|
|
||||||
|
def main(fn=None):
|
||||||
|
if fn:
|
||||||
|
sys.exit(pytest.main([fn]))
|
||||||
|
else:
|
||||||
|
unittests_main()
|
||||||
|
|
||||||
|
class TestCase(VanillaTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
chdir(dirname(realpath(__file__)) + '/..')
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
disableLogging()
|
||||||
|
initLogging()
|
||||||
|
|
||||||
|
class CapturingTestCase(TestCase):
|
||||||
|
"""
|
||||||
|
A TestCase that needs to capture stderr/stdout and invoke click CLI.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _setup_pytest_capfd(self, capfd):
|
||||||
|
self.capfd = capfd
|
||||||
|
|
||||||
|
def invoke_cli(self, cli, args):
|
||||||
|
"""
|
||||||
|
Substitution for click.CliRunner.invooke that works together nicely
|
||||||
|
with unittests/pytest capturing stdout/stderr.
|
||||||
|
"""
|
||||||
|
self.capture_out_err() # XXX snapshot just before executing the CLI
|
||||||
|
code = 0
|
||||||
|
sys.argv[1:] = args # XXX necessary because sys.argv reflects pytest args not cli args
|
||||||
|
try:
|
||||||
|
cli.main(args=args)
|
||||||
|
except SystemExit as e:
|
||||||
|
code = e.code
|
||||||
|
out, err = self.capture_out_err()
|
||||||
|
return code, out, err
|
||||||
|
|
||||||
|
def capture_out_err(self):
|
||||||
|
return self.capfd.readouterr()
|
24
tests/test_run.py
Normal file
24
tests/test_run.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from os import environ
|
||||||
|
from pathlib import Path
|
||||||
|
from ocrd_utils import pushd_popd
|
||||||
|
from tests.base import CapturingTestCase as TestCase, main
|
||||||
|
from sbb_newspapers_org_image.cli import main as eynollah_cli
|
||||||
|
|
||||||
|
testdir = Path(__file__).parent.resolve()
|
||||||
|
|
||||||
|
EYNOLLAH_MODELS = environ.get('EYNOLLAH_MODELS', str(testdir.joinpath('..', 'models_eynollah').resolve()))
|
||||||
|
|
||||||
|
class TestEynollahRun(TestCase):
|
||||||
|
|
||||||
|
def test_full_run(self):
|
||||||
|
with pushd_popd(tempdir=True) as tempdir:
|
||||||
|
code, out, err = self.invoke_cli(eynollah_cli, [
|
||||||
|
'-m', EYNOLLAH_MODELS,
|
||||||
|
'-i', str(testdir.joinpath('resources/kant_aufklaerung_1784_0020.tif')),
|
||||||
|
'-o', tempdir
|
||||||
|
])
|
||||||
|
print(code, out, err)
|
||||||
|
assert not code
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(__file__)
|
Loading…
Add table
Add a link
Reference in a new issue