Tighten ruff rules and modernize style

This commit is contained in:
James R. Barlow
2026-01-27 14:04:52 -08:00
parent 6b37583674
commit c5d3ef4b17
22 changed files with 104 additions and 77 deletions
+4 -3
View File
@@ -23,9 +23,10 @@ class Gs106WarningFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
# Allow all records except the expected Ghostscript 10.6.x warning
if "Ghostscript 10.6.x contains JPEG encoding errors" in record.getMessage():
return False
return True
return (
"Ghostscript 10.6.x contains JPEG encoding errors"
not in record.getMessage()
)
@pytest.fixture(autouse=True)
+1
View File
@@ -1,4 +1,5 @@
"""Test JSON serialization of OcrOptions for multiprocessing compatibility."""
from __future__ import annotations
import multiprocessing
from io import BytesIO
+2 -6
View File
@@ -3,9 +3,8 @@
from __future__ import annotations
import datetime
import datetime as dt
import warnings
from datetime import timezone
from shutil import copyfile
import pikepdf
@@ -198,10 +197,7 @@ def test_creation_date_preserved(output_type, resources, infile, outpdf):
# We expect that the modified date is quite recent
date_after = decode_pdf_date(str(after['/ModDate']))
assert (
seconds_between_dates(date_after, datetime.datetime.now(timezone.utc))
< 1000
)
assert seconds_between_dates(date_after, dt.datetime.now(dt.UTC)) < 1000
@pytest.fixture
+1
View File
@@ -10,6 +10,7 @@ This tests the fpdf2 renderer with various language groups:
- CJK (Chinese Simplified/Traditional, Japanese, Korean)
- Devanagari (Hindi, Sanskrit)
"""
from __future__ import annotations
import shutil
import subprocess
+1 -1
View File
@@ -119,7 +119,7 @@ def test_unpaper_args_invalid(resources, outpdf):
def test_unpaper_image_too_big(resources, outdir, caplog):
with patch('ocrmypdf._exec.unpaper.UNPAPER_IMAGE_PIXEL_LIMIT', 42):
infile = resources / 'crom.png'
unpaper.clean(infile, outdir / 'out.png', dpi=300) == infile
assert unpaper.clean(infile, outdir / 'out.png', dpi=300) == infile
assert any(
'too large for cleaning' in rec.message
+5 -3
View File
@@ -1,4 +1,6 @@
import datetime
from __future__ import annotations
import datetime as dt
import os
import shutil
import subprocess
@@ -43,8 +45,8 @@ def test_watcher(tmp_path, resources, year_month):
if year_month:
assert (
output_dir
/ f'{datetime.date.today().year}'
/ f'{datetime.date.today().month:02d}'
/ f'{dt.date.today().year}'
/ f'{dt.date.today().month:02d}'
/ 'trivial.pdf'
).exists()
else: