1
0
Fork 0
mirror of https://github.com/qurator-spk/dinglehopper.git synced 2025-07-11 03:19:57 +02:00
dinglehopper/qurator/dinglehopper/tests/util.py
Gerber, Mike f94e8b9b1c Revert "Merge branch 'master' of https://github.com/qurator-spk/sbb_textline_detector"
This reverts commit a3c1eee8f31349edcfb1e36920763bcecceb1129, reversing
changes made to dc76213ffc1fbabc2c45f0e52ced55449bdf2e83.
2019-12-09 12:44:05 +01:00

38 lines
814 B
Python

from itertools import zip_longest
from typing import Iterable
import colorama
import os
def diffprint(x, y):
"""Print elements or lists x and y, with differences in red"""
def _diffprint(x, y):
if x != y:
print(colorama.Fore.RED, x, y, colorama.Fore.RESET)
else:
print(x, y)
if isinstance(x, Iterable):
for xe, ye in zip_longest(x, y):
_diffprint(xe, ye)
else:
_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)