Convert to a pytest style test

fix/readme-no-checkpoint
Gerber, Mike 5 years ago
parent 2393edc645
commit e07b333db1

@ -3,24 +3,22 @@ import shutil
import subprocess import subprocess
import urllib.request import urllib.request
from test.base import TestCase, main, assets, skip import pytest
from ocrd.resolver import Resolver from ocrd.resolver import Resolver
from ocrd_calamari import CalamariRecognize from ocrd_calamari import CalamariRecognize
from test.base import main, assets
METS_KANT = assets.url_of('kant_aufklaerung_1784-page-block-line-word_glyph/data/mets.xml') METS_KANT = assets.url_of('kant_aufklaerung_1784-page-block-line-word_glyph/data/mets.xml')
WORKSPACE_DIR = '/tmp/test-ocrd-calamari' WORKSPACE_DIR = '/tmp/test-ocrd-calamari'
class TestCalamariRecognize(TestCase):
def setUp(self): @pytest.fixture
def workspace():
if os.path.exists(WORKSPACE_DIR): if os.path.exists(WORKSPACE_DIR):
shutil.rmtree(WORKSPACE_DIR) shutil.rmtree(WORKSPACE_DIR)
os.makedirs(WORKSPACE_DIR) os.makedirs(WORKSPACE_DIR)
def runTest(self):
resolver = Resolver() resolver = Resolver()
workspace = resolver.workspace_from_url(METS_KANT, dst_dir=WORKSPACE_DIR) workspace = resolver.workspace_from_url(METS_KANT, dst_dir=WORKSPACE_DIR)
@ -32,6 +30,10 @@ class TestCalamariRecognize(TestCase):
"https://github.com/OCR-D/assets/raw/master/data/kant_aufklaerung_1784/data/OCR-D-IMG/" + f, "https://github.com/OCR-D/assets/raw/master/data/kant_aufklaerung_1784/data/OCR-D-IMG/" + f,
os.path.join(WORKSPACE_DIR, 'OCR-D-IMG', f)) os.path.join(WORKSPACE_DIR, 'OCR-D-IMG', f))
return workspace
def test_recognize(workspace):
# The binarization options I have are: # The binarization options I have are:
# #
# a. ocrd_kraken which tries to install cltsm, whose installation is borken on my machine (protobuf) # a. ocrd_kraken which tries to install cltsm, whose installation is borken on my machine (protobuf)
@ -57,9 +59,10 @@ class TestCalamariRecognize(TestCase):
workspace.save_mets() workspace.save_mets()
page1 = os.path.join(workspace.directory, 'OCR-D-OCR-CALAMARI/OCR-D-OCR-CALAMARI_0001.xml') page1 = os.path.join(workspace.directory, 'OCR-D-OCR-CALAMARI/OCR-D-OCR-CALAMARI_0001.xml')
self.assertTrue(os.path.exists(page1)) assert os.path.exists(page1)
with open(page1, 'r', encoding='utf-8') as f: with open(page1, 'r', encoding='utf-8') as f:
self.assertIn('verſchuldeten', f.read()) assert 'verſchuldeten' in f.read()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save