mirror of
https://github.com/qurator-spk/dinglehopper.git
synced 2025-07-01 06:29:59 +02:00
🎨 dinglehopper: Move working_directory() context manager into tests/util
This commit is contained in:
parent
f98c527c93
commit
5ccdace1dd
3 changed files with 16 additions and 26 deletions
|
@ -2,23 +2,11 @@ import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from .util import working_directory
|
||||||
|
|
||||||
from ..cli import process
|
from ..cli import process
|
||||||
|
|
||||||
|
|
||||||
class working_directory:
|
|
||||||
"""Context manager to temporarily change the working directory"""
|
|
||||||
def __init__(self, wd):
|
|
||||||
self.wd = wd
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
self.old_wd = os.getcwd()
|
|
||||||
os.chdir(self.wd)
|
|
||||||
|
|
||||||
def __exit__(self, etype, value, traceback):
|
|
||||||
os.chdir(self.old_wd)
|
|
||||||
|
|
||||||
|
|
||||||
def test_cli_json(tmp_path):
|
def test_cli_json(tmp_path):
|
||||||
"""Test that the cli/process() yields a loadable JSON report"""
|
"""Test that the cli/process() yields a loadable JSON report"""
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
import pytest
|
import pytest
|
||||||
|
from .util import working_directory
|
||||||
|
|
||||||
|
|
||||||
from ..ocrd_cli import ocrd_dinglehopper
|
from ..ocrd_cli import ocrd_dinglehopper
|
||||||
|
@ -13,19 +14,6 @@ from ..ocrd_cli import ocrd_dinglehopper
|
||||||
data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
|
data_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
|
||||||
|
|
||||||
|
|
||||||
class working_directory:
|
|
||||||
"""Context manager to temporarily change the working directory"""
|
|
||||||
def __init__(self, wd):
|
|
||||||
self.wd = wd
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
self.old_wd = os.getcwd()
|
|
||||||
os.chdir(self.wd)
|
|
||||||
|
|
||||||
def __exit__(self, etype, value, traceback):
|
|
||||||
os.chdir(self.old_wd)
|
|
||||||
|
|
||||||
|
|
||||||
def test_ocrd_cli(tmp_path):
|
def test_ocrd_cli(tmp_path):
|
||||||
"""Test OCR-D interface"""
|
"""Test OCR-D interface"""
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from itertools import zip_longest
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def diffprint(x, y):
|
def diffprint(x, y):
|
||||||
|
@ -22,3 +23,16 @@ def diffprint(x, y):
|
||||||
|
|
||||||
def unzip(l):
|
def unzip(l):
|
||||||
return zip(*l)
|
return zip(*l)
|
||||||
|
|
||||||
|
|
||||||
|
class working_directory:
|
||||||
|
"""Context manager to temporarily change the working directory"""
|
||||||
|
def __init__(self, wd):
|
||||||
|
self.wd = wd
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.old_wd = os.getcwd()
|
||||||
|
os.chdir(self.wd)
|
||||||
|
|
||||||
|
def __exit__(self, etype, value, traceback):
|
||||||
|
os.chdir(self.old_wd)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue