From 5ccdace1dd7e9f729458a1a1a2dfd33fcf81b355 Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Mon, 2 Dec 2019 15:18:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20dinglehopper:=20Move=20working?= =?UTF-8?q?=5Fdirectory()=20context=20manager=20into=20tests/util?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/test_integ_cli_valid_json.py | 14 +------------- qurator/dinglehopper/tests/test_integ_ocrd_cli.py | 14 +------------- qurator/dinglehopper/tests/util.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/qurator/dinglehopper/tests/test_integ_cli_valid_json.py b/qurator/dinglehopper/tests/test_integ_cli_valid_json.py index 9302463..5699700 100644 --- a/qurator/dinglehopper/tests/test_integ_cli_valid_json.py +++ b/qurator/dinglehopper/tests/test_integ_cli_valid_json.py @@ -2,23 +2,11 @@ import os import json import pytest +from .util import working_directory 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): """Test that the cli/process() yields a loadable JSON report""" diff --git a/qurator/dinglehopper/tests/test_integ_ocrd_cli.py b/qurator/dinglehopper/tests/test_integ_ocrd_cli.py index 75e847e..41da748 100644 --- a/qurator/dinglehopper/tests/test_integ_ocrd_cli.py +++ b/qurator/dinglehopper/tests/test_integ_ocrd_cli.py @@ -6,6 +6,7 @@ from pathlib import Path from click.testing import CliRunner import pytest +from .util import working_directory 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') -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): """Test OCR-D interface""" diff --git a/qurator/dinglehopper/tests/util.py b/qurator/dinglehopper/tests/util.py index cb4dc13..52b7506 100644 --- a/qurator/dinglehopper/tests/util.py +++ b/qurator/dinglehopper/tests/util.py @@ -2,6 +2,7 @@ from itertools import zip_longest from typing import Iterable import colorama +import os def diffprint(x, y): @@ -22,3 +23,16 @@ def diffprint(x, y): def unzip(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)