Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ repos:
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
- id: ruff-format

- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ lint:

.PHONY: lint-fix
lint-fix:
python3 -c "import black" > /dev/null 2>&1 || python3 -m pip install black
python3 -m black .
python3 -c "import ruff" > /dev/null 2>&1 || python3 -m pip install ruff
python3 -m ruff --fix .
python3 -m ruff check --fix .
python3 -m ruff format .
Comment on lines +118 to +119
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python3 -m ruff check --fix .
python3 -m ruff format .
python3 -m ruff check --fix
python3 -m ruff format

See astral-sh/ruff#10217


.PHONY: mypy
mypy:
Expand Down
7 changes: 2 additions & 5 deletions Tests/check_jpeg_leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@

"""


# fmt: off
standard_l_qtable = (
# fmt: off
16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56,
Expand All @@ -87,11 +86,9 @@
24, 35, 55, 64, 81, 104, 113, 92,
49, 64, 78, 87, 103, 121, 120, 101,
72, 92, 95, 98, 112, 100, 103, 99,
# fmt: on
)

standard_chrominance_qtable = (
# fmt: off
17, 18, 24, 47, 99, 99, 99, 99,
18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99,
Expand All @@ -100,8 +97,8 @@
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
# fmt: on
)
# fmt: on


@pytest.mark.parametrize(
Expand Down
5 changes: 2 additions & 3 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ def assert_image_similar(
ave_diff = diff / (a.size[0] * a.size[1])
try:
assert epsilon >= ave_diff, (
(msg or "")
+ f" average pixel value difference {ave_diff:.4f} > epsilon {epsilon:.4f}"
)
msg or ""
) + f" average pixel value difference {ave_diff:.4f} > epsilon {epsilon:.4f}"
except Exception as e:
try:
url = upload(a, b)
Expand Down
40 changes: 20 additions & 20 deletions Tests/test_box_blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,138 +72,138 @@ def test_color_modes() -> None:


def test_radius_0() -> None:
# fmt: off
assert_blur(
sample,
0,
[
# fmt: off
[210, 50, 20, 10, 220, 230, 80],
[190, 210, 20, 180, 170, 40, 110],
[120, 210, 250, 60, 220, 0, 220],
[220, 40, 230, 80, 130, 250, 40],
[250, 0, 80, 30, 60, 20, 110],
# fmt: on
],
)
# fmt: on


def test_radius_0_02() -> None:
# fmt: off
assert_blur(
sample,
0.02,
[
# fmt: off
[206, 55, 20, 17, 215, 223, 83],
[189, 203, 31, 171, 169, 46, 110],
[125, 206, 241, 69, 210, 13, 210],
[215, 49, 221, 82, 131, 235, 48],
[244, 7, 80, 32, 60, 27, 107],
# fmt: on
],
delta=2,
)
# fmt: on


def test_radius_0_05() -> None:
# fmt: off
assert_blur(
sample,
0.05,
[
# fmt: off
[202, 62, 22, 27, 209, 215, 88],
[188, 194, 44, 161, 168, 56, 111],
[131, 201, 229, 81, 198, 31, 198],
[209, 62, 209, 86, 133, 216, 59],
[237, 17, 80, 36, 60, 35, 103],
# fmt: on
],
delta=2,
)
# fmt: on


def test_radius_0_1() -> None:
# fmt: off
assert_blur(
sample,
0.1,
[
# fmt: off
[196, 72, 24, 40, 200, 203, 93],
[187, 183, 62, 148, 166, 68, 111],
[139, 193, 213, 96, 182, 54, 182],
[201, 78, 193, 91, 133, 191, 73],
[227, 31, 80, 42, 61, 47, 99],
# fmt: on
],
delta=1,
)
# fmt: on


def test_radius_0_5() -> None:
# fmt: off
assert_blur(
sample,
0.5,
[
# fmt: off
[176, 101, 46, 83, 163, 165, 111],
[176, 149, 108, 122, 144, 120, 117],
[164, 171, 159, 141, 134, 119, 129],
[170, 136, 133, 114, 116, 124, 109],
[184, 95, 72, 70, 69, 81, 89],
# fmt: on
],
delta=1,
)
# fmt: on


def test_radius_1() -> None:
# fmt: off
assert_blur(
sample,
1,
[
# fmt: off
[170, 109, 63, 97, 146, 153, 116],
[168, 142, 112, 128, 126, 143, 121],
[169, 166, 142, 149, 126, 131, 114],
[159, 156, 109, 127, 94, 117, 112],
[164, 128, 63, 87, 76, 89, 90],
# fmt: on
],
delta=1,
)
# fmt: on


def test_radius_1_5() -> None:
# fmt: off
assert_blur(
sample,
1.5,
[
# fmt: off
[155, 120, 105, 112, 124, 137, 130],
[160, 136, 124, 125, 127, 134, 130],
[166, 147, 130, 125, 120, 121, 119],
[168, 145, 119, 109, 103, 105, 110],
[168, 134, 96, 85, 85, 89, 97],
# fmt: on
],
delta=1,
)
# fmt: on


def test_radius_bigger_then_half() -> None:
# fmt: off
assert_blur(
sample,
3,
[
# fmt: off
[144, 145, 142, 128, 114, 115, 117],
[148, 145, 137, 122, 109, 111, 112],
[152, 145, 131, 117, 103, 107, 108],
[156, 144, 126, 111, 97, 102, 103],
[160, 144, 121, 106, 92, 98, 99],
# fmt: on
],
delta=1,
)
# fmt: on


def test_radius_bigger_then_width() -> None:
Expand Down Expand Up @@ -237,36 +237,36 @@ def test_extreme_large_radius() -> None:


def test_two_passes() -> None:
# fmt: off
assert_blur(
sample,
1,
[
# fmt: off
[153, 123, 102, 109, 132, 135, 129],
[159, 138, 123, 121, 133, 131, 126],
[162, 147, 136, 124, 127, 121, 121],
[159, 140, 125, 108, 111, 106, 108],
[154, 126, 105, 87, 94, 93, 97],
# fmt: on
],
passes=2,
delta=1,
)
# fmt: on


def test_three_passes() -> None:
# fmt: off
assert_blur(
sample,
1,
[
# fmt: off
[146, 131, 116, 118, 126, 131, 130],
[151, 138, 125, 123, 126, 128, 127],
[154, 143, 129, 123, 120, 120, 119],
[152, 139, 122, 113, 108, 108, 108],
[148, 132, 112, 102, 97, 99, 100],
# fmt: on
],
passes=3,
delta=1,
)
# fmt: on
10 changes: 3 additions & 7 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,7 @@ def _n_qtables_helper(n: int, test_file: str) -> None:
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99
""".split(
None
)
""".split(None)
]

standard_chrominance_qtable = [
Expand All @@ -593,9 +591,7 @@ def _n_qtables_helper(n: int, test_file: str) -> None:
99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99
99 99 99 99 99 99 99 99
""".split(
None
)
""".split(None)
]
# list of qtable lists
assert_image_similar(
Expand Down Expand Up @@ -921,7 +917,7 @@ def test_icc_after_SOF(self) -> None:

def test_jpeg_magic_number(self, monkeypatch: pytest.MonkeyPatch) -> None:
size = 4097
buffer = BytesIO(b"\xFF" * size) # Many xFF bytes
buffer = BytesIO(b"\xff" * size) # Many FF bytes
max_pos = 0
orig_read = buffer.read

Expand Down
3 changes: 1 addition & 2 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class Tc(NamedTuple):
}

def check_tags(
tiffinfo: TiffImagePlugin.ImageFileDirectory_v2 | dict[int, str]
tiffinfo: TiffImagePlugin.ImageFileDirectory_v2 | dict[int, str],
) -> None:
im = hopper()

Expand Down Expand Up @@ -626,7 +626,6 @@ def test_4bit(self, monkeypatch: pytest.MonkeyPatch) -> None:
# Act
monkeypatch.setattr(TiffImagePlugin, "READ_LIBTIFF", True)
with Image.open(test_file) as im:

# Assert
assert im.size == (128, 128)
assert im.mode == "L"
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_pdf_append(tmp_path: Path) -> None:
# append some info
pdf.info.Title = "abc"
pdf.info.Author = "def"
pdf.info.Subject = "ghi\uABCD"
pdf.info.Subject = "ghi\uabcd"
pdf.info.Keywords = "qw)e\\r(ty"
pdf.info.Creator = "hopper()"
pdf.start_writing()
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_pdf_append(tmp_path: Path) -> None:
assert pdf.info.Title == "abc"
assert pdf.info.Producer == "PdfParser"
assert pdf.info.Keywords == "qw)e\\r(ty"
assert pdf.info.Subject == "ghi\uABCD"
assert pdf.info.Subject == "ghi\uabcd"
assert b"CreationDate" in pdf.info
assert b"ModDate" in pdf.info
check_pdf_pages_consistency(pdf)
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_ppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_sanity() -> None:
(b"P5 3 1 257 \x00\x00\x00\x80\x01\x01", "I", (0, 32640, 65535)),
# P6 with maxval < 255
(
b"P6 3 1 17 \x00\x01\x02\x08\x09\x0A\x0F\x10\x11",
b"P6 3 1 17 \x00\x01\x02\x08\x09\x0a\x0f\x10\x11",
"RGB",
(
(0, 15, 30),
Expand All @@ -60,7 +60,7 @@ def test_sanity() -> None:
# P6 with maxval > 255
(
b"P6 3 1 257 \x00\x00\x00\x01\x00\x02"
b"\x00\x80\x00\x81\x00\x82\x01\x00\x01\x01\xFF\xFF",
b"\x00\x80\x00\x81\x00\x82\x01\x00\x01\x01\xff\xff",
"RGB",
(
(0, 1, 2),
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_font_leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def _test_font(self, font: ImageFont.FreeTypeFont | ImageFont.ImageFont) -> None
draw = ImageDraw.ImageDraw(im)
self._test_leak(
lambda: draw.text(
(0, 0), "some text " * 1024, font=font, fill="black" # ~10k
(0, 0),
"some text " * 1024, # ~10k
font=font,
fill="black",
)
)

Expand Down
Loading