The Great Logging Refactor

Remove all instances of logger object being passed as parameters.
This was a holdover from ruffus, and complicated a lot of simple things.
This commit is contained in:
James R. Barlow
2020-04-14 23:59:33 -07:00
parent 4ff4ed24a8
commit d146d2b65c
19 changed files with 107 additions and 199 deletions
-4
View File
@@ -73,14 +73,12 @@ def test_rasterize_size(francais, outdir, caplog):
target_size = Decimal('50.0'), Decimal('30.0')
forced_dpi = 42.0, 4242.0
log = logging.getLogger()
rasterize_pdf(
path,
outdir / 'out.png',
target_size[0] / page_size[0],
target_size[1] / page_size[1],
raster_device='pngmono',
log=log,
page_dpi=forced_dpi,
)
@@ -97,7 +95,6 @@ def test_rasterize_rotated(francais, outdir, caplog):
target_size = Decimal('50.0'), Decimal('30.0')
forced_dpi = 42.0, 4242.0
log = logging.getLogger()
caplog.set_level(logging.DEBUG)
rasterize_pdf(
path,
@@ -105,7 +102,6 @@ def test_rasterize_rotated(francais, outdir, caplog):
target_size[0] / page_size[0],
target_size[1] / page_size[1],
raster_device='pngmono',
log=log,
page_dpi=forced_dpi,
rotation=90,
)
+1 -6
View File
@@ -43,12 +43,7 @@ def test_mono_not_inverted(resources, outdir):
opt.main(infile, outdir / 'out.pdf', level=3)
rasterize_pdf(
outdir / 'out.pdf',
outdir / 'im.png',
xres=10,
yres=10,
raster_device='pnggray',
log=logging.getLogger(name='test_mono_not_inverted'),
outdir / 'out.pdf', outdir / 'im.png', xres=10, yres=10, raster_device='pnggray'
)
with Image.open(fspath(outdir / 'im.png')) as im:
+1 -10
View File
@@ -55,7 +55,6 @@ def test_deskew(spoof_tesseract_noop, resources, outdir):
xres=150,
yres=150,
raster_device='pngmono',
log=log,
pageno=1,
)
@@ -80,18 +79,10 @@ def test_remove_background(spoof_tesseract_noop, resources, outdir):
env=spoof_tesseract_noop,
)
log = logging.getLogger()
output_png = outdir / 'remove_bg.png'
ghostscript.rasterize_pdf(
output_pdf,
output_png,
xres=100,
yres=100,
raster_device='png16m',
log=log,
pageno=1,
output_pdf, output_png, xres=100, yres=100, raster_device='png16m', pageno=1
)
# The output image should contain pure white and black
+1 -5
View File
@@ -48,8 +48,6 @@ RENDERERS = ['hocr', 'sandwich']
def check_monochrome_correlation(
outdir, reference_pdf, reference_pageno, test_pdf, test_pageno
):
gslog = logging.getLogger()
reference_png = outdir / f'{reference_pdf.name}.ref{reference_pageno:04d}.png'
test_png = outdir / f'{test_pdf.name}.test{test_pageno:04d}.png'
@@ -63,7 +61,6 @@ def check_monochrome_correlation(
xres=100,
yres=100,
raster_device='pngmono',
log=gslog,
pageno=pageno,
rotation=0,
)
@@ -268,7 +265,6 @@ def test_tesseract_orientation(resources, tmp_path):
pix_rotated = pix.rotate_orth(2) # 180 degrees clockwise
pix_rotated.write_implied_format(tmp_path / '000001.png')
log = logging.getLogger()
tesseract.get_orientation( # Test results of this are unreliable
tmp_path / '000001.png', engine_mode='3', timeout=10, log=log
tmp_path / '000001.png', engine_mode='3', timeout=10
)
+1 -1
View File
@@ -74,7 +74,7 @@ def test_stdout(spoof_tesseract_noop, ocrmypdf_exec, resources, outpdf):
)
assert p.returncode == ExitCode.ok
assert qpdf.check(output_file, log=None)
assert qpdf.check(output_file)
@pytest.mark.skipif(
+4 -14
View File
@@ -86,8 +86,6 @@ def test_no_languages(tmp_path):
def test_image_too_large_hocr(monkeypatch, resources, outdir):
log = logging.getLogger('test_image_too_large_hocr')
def dummy_run(args, *, env=None, **kwargs):
raise subprocess.CalledProcessError(1, 'tesseract', output=b'Image too large')
@@ -100,7 +98,6 @@ def test_image_too_large_hocr(monkeypatch, resources, outdir):
tessconfig=[],
timeout=180.0,
pagesegmode=None,
log=log,
user_words=None,
user_patterns=None,
tesseract_env=None,
@@ -109,8 +106,6 @@ def test_image_too_large_hocr(monkeypatch, resources, outdir):
def test_image_too_large_pdf(monkeypatch, resources, outdir):
log = logging.getLogger('test_image_too_large_pdf')
def dummy_run(args, *, env=None, **kwargs):
raise subprocess.CalledProcessError(1, 'tesseract', output=b'Image too large')
@@ -126,7 +121,6 @@ def test_image_too_large_pdf(monkeypatch, resources, outdir):
tessconfig=[],
timeout=180.0,
pagesegmode=None,
log=log,
user_words=None,
user_patterns=None,
tesseract_env=None,
@@ -137,8 +131,7 @@ def test_image_too_large_pdf(monkeypatch, resources, outdir):
def test_timeout(caplog):
log = logging.getLogger('test_timeout')
tesseract.page_timedout(log, '123456.png', 5)
tesseract.page_timedout('123456.png', 5)
assert "123456" in caplog.text
assert "took too long" in caplog.text
@@ -160,10 +153,8 @@ def test_timeout(caplog):
],
)
def test_tesseract_log_output(caplog, in_, logged):
log = logging.getLogger('tesseract_log_output')
log.setLevel(logging.INFO)
tesseract.tesseract_log_output(log, in_, 'dummy')
caplog.set_level(logging.INFO)
tesseract.tesseract_log_output(in_, 'dummy')
if logged == '':
assert caplog.text == ''
else:
@@ -171,7 +162,6 @@ def test_tesseract_log_output(caplog, in_, logged):
def test_tesseract_log_output_raises(caplog):
log = logging.getLogger('tesseract_log_output')
with pytest.raises(tesseract.TesseractConfigError):
tesseract.tesseract_log_output(log, b'parameter not found: moo', 'dummy')
tesseract.tesseract_log_output(b'parameter not found: moo', 'dummy')
assert 'not found' in caplog.text