Skip to content

Commit

Permalink
Black 23.11.0 --preview
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 6, 2023
1 parent f505eec commit f8b357f
Show file tree
Hide file tree
Showing 42 changed files with 308 additions and 308 deletions.
1 change: 1 addition & 0 deletions .github/workflows/system-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Requested here:
https://github.com/actions/virtual-environments/issues/79
"""

import os
import platform
import sys
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repos:
rev: 23.11.0
hooks:
- id: black
args: [--preview]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
Expand Down
1 change: 1 addition & 0 deletions Tests/test_file_dds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test DdsImagePlugin"""

from io import BytesIO

import pytest
Expand Down
20 changes: 5 additions & 15 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,7 @@ def _n_qtables_helper(n, test_file):
assert im2.quantization == {0: bounds_qtable}

# values from wizard.txt in jpeg9-a src package.
standard_l_qtable = [
int(s)
for s in """
standard_l_qtable = [int(s) for s in """
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 @@ -546,14 +544,9 @@ def _n_qtables_helper(n, test_file):
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 = [
int(s)
for s in """
standard_chrominance_qtable = [int(s) for s in """
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 @@ -562,10 +555,7 @@ def _n_qtables_helper(n, test_file):
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(
im,
Expand Down Expand Up @@ -886,7 +876,7 @@ def test_icc_after_SOF(self):

def test_jpeg_magic_number(self):
size = 4097
buffer = BytesIO(b"\xFF" * size) # Many xFF bytes
buffer = BytesIO(b"\xff" * size) # Many xFF bytes
buffer.max_pos = 0
orig_read = buffer.read

Expand Down
68 changes: 32 additions & 36 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,35 +243,33 @@ def test_custom_metadata(self, tmp_path):
tc = namedtuple("test_case", "value,type,supported_by_default")
custom = {
37000 + k: v
for k, v in enumerate(
[
tc(4, TiffTags.SHORT, True),
tc(123456789, TiffTags.LONG, True),
tc(-4, TiffTags.SIGNED_BYTE, False),
tc(-4, TiffTags.SIGNED_SHORT, False),
tc(-123456789, TiffTags.SIGNED_LONG, False),
tc(TiffImagePlugin.IFDRational(4, 7), TiffTags.RATIONAL, True),
tc(4.25, TiffTags.FLOAT, True),
tc(4.25, TiffTags.DOUBLE, True),
tc("custom tag value", TiffTags.ASCII, True),
tc(b"custom tag value", TiffTags.BYTE, True),
tc((4, 5, 6), TiffTags.SHORT, True),
tc((123456789, 9, 34, 234, 219387, 92432323), TiffTags.LONG, True),
tc((-4, 9, 10), TiffTags.SIGNED_BYTE, False),
tc((-4, 5, 6), TiffTags.SIGNED_SHORT, False),
tc(
(-123456789, 9, 34, 234, 219387, -92432323),
TiffTags.SIGNED_LONG,
False,
),
tc((4.25, 5.25), TiffTags.FLOAT, True),
tc((4.25, 5.25), TiffTags.DOUBLE, True),
# array of TIFF_BYTE requires bytes instead of tuple for backwards
# compatibility
tc(bytes([4]), TiffTags.BYTE, True),
tc(bytes((4, 9, 10)), TiffTags.BYTE, True),
]
)
for k, v in enumerate([
tc(4, TiffTags.SHORT, True),
tc(123456789, TiffTags.LONG, True),
tc(-4, TiffTags.SIGNED_BYTE, False),
tc(-4, TiffTags.SIGNED_SHORT, False),
tc(-123456789, TiffTags.SIGNED_LONG, False),
tc(TiffImagePlugin.IFDRational(4, 7), TiffTags.RATIONAL, True),
tc(4.25, TiffTags.FLOAT, True),
tc(4.25, TiffTags.DOUBLE, True),
tc("custom tag value", TiffTags.ASCII, True),
tc(b"custom tag value", TiffTags.BYTE, True),
tc((4, 5, 6), TiffTags.SHORT, True),
tc((123456789, 9, 34, 234, 219387, 92432323), TiffTags.LONG, True),
tc((-4, 9, 10), TiffTags.SIGNED_BYTE, False),
tc((-4, 5, 6), TiffTags.SIGNED_SHORT, False),
tc(
(-123456789, 9, 34, 234, 219387, -92432323),
TiffTags.SIGNED_LONG,
False,
),
tc((4.25, 5.25), TiffTags.FLOAT, True),
tc((4.25, 5.25), TiffTags.DOUBLE, True),
# array of TIFF_BYTE requires bytes instead of tuple for backwards
# compatibility
tc(bytes([4]), TiffTags.BYTE, True),
tc(bytes((4, 9, 10)), TiffTags.BYTE, True),
])
}

libtiffs = [False]
Expand Down Expand Up @@ -311,13 +309,11 @@ def check_tags(tiffinfo):

# Test without types. This only works for some types, int for example are
# always encoded as LONG and not SIGNED_LONG.
check_tags(
{
tag: tagdata.value
for tag, tagdata in custom.items()
if tagdata.supported_by_default
}
)
check_tags({
tag: tagdata.value
for tag, tagdata in custom.items()
if tagdata.supported_by_default
})
TiffImagePlugin.WRITE_LIBTIFF = False

def test_subifd(self, tmp_path):
Expand Down
1 change: 0 additions & 1 deletion Tests/test_file_libtiff_small.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class TestFileLibTiffSmall(LibTiffTestCase):

"""The small lena image was failing on open in the libtiff
decoder because the file pointer was set to the wrong place
by a spurious seek. It wasn't failing with the byteio method.
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 @@ -258,7 +258,7 @@ def test_pdf_append(tmp_path):
# 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 @@ -286,7 +286,7 @@ def test_pdf_append(tmp_path):
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
8 changes: 5 additions & 3 deletions Tests/test_file_ppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_sanity():
(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 @@ -51,8 +51,10 @@ def test_sanity():
),
# 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"P6 3 1 257 \x00\x00\x00\x01\x00\x02"
b"\x00\x80\x00\x81\x00\x82\x01\x00\x01\x01\xff\xff"
),
"RGB",
(
(0, 1, 2),
Expand Down
20 changes: 9 additions & 11 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,15 @@ def test_ne(self):
def test_alpha_composite(self):
# https://stackoverflow.com/questions/3374878
# Arrange
expected_colors = sorted(
[
(1122, (128, 127, 0, 255)),
(1089, (0, 255, 0, 255)),
(3300, (255, 0, 0, 255)),
(1156, (170, 85, 0, 192)),
(1122, (0, 255, 0, 128)),
(1122, (255, 0, 0, 128)),
(1089, (0, 255, 0, 0)),
]
)
expected_colors = sorted([
(1122, (128, 127, 0, 255)),
(1089, (0, 255, 0, 255)),
(3300, (255, 0, 0, 255)),
(1156, (170, 85, 0, 192)),
(1122, (0, 255, 0, 128)),
(1122, (255, 0, 0, 128)),
(1089, (0, 255, 0, 0)),
])

dst = Image.new("RGBA", size=(100, 100), color=(0, 255, 0, 255))
draw = ImageDraw.Draw(dst)
Expand Down
11 changes: 3 additions & 8 deletions Tests/test_image_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def test_list(self):
assert im.getpixel([0, 0]) == (20, 20, 70)

@pytest.mark.parametrize("mode", ("I;16", "I;16B"))
@pytest.mark.parametrize(
"expected_color", (2**15 - 1, 2**15, 2**15 + 1, 2**16 - 1)
)
@pytest.mark.parametrize("expected_color", (2**15 - 1, 2**15, 2**15 + 1, 2**16 - 1))
def test_signedness(self, mode, expected_color):
# see https://github.com/python-pillow/Pillow/issues/452
# pixelaccess is using signed int* instead of uint*
Expand Down Expand Up @@ -431,8 +429,7 @@ def test_embeddable(self):
from setuptools.command.build_ext import new_compiler

with open("embed_pil.c", "w", encoding="utf-8") as fh:
fh.write(
"""
fh.write("""
#include "Python.h"
int main(int argc, char* argv[])
Expand All @@ -453,9 +450,7 @@ def test_embeddable(self):
return 0;
}
"""
% sys.prefix.replace("\\", "\\\\")
)
""" % sys.prefix.replace("\\", "\\\\"))

compiler = new_compiler()
compiler.add_include_dir(sysconfig.get_config_var("INCLUDEPY"))
Expand Down
3 changes: 1 addition & 2 deletions Tests/test_image_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ def run_dirty_case(self, i, clean_pixel):
for x in range(i.size[0]):
if px[x, y][-1] != 0 and px[x, y][:-1] != clean_pixel:
message = (
f"pixel at ({x}, {y}) is different:\n"
f"{px[x, y]}\n{clean_pixel}"
f"pixel at ({x}, {y}) is different:\n{px[x, y]}\n{clean_pixel}"
)
assert px[x, y][:3] == clean_pixel, message

Expand Down
1 change: 1 addition & 0 deletions Tests/test_image_resize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for resize functionality.
"""

from itertools import permutations

import pytest
Expand Down
8 changes: 5 additions & 3 deletions Tests/test_imagecms.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,11 @@ def assert_truncated_tuple_equal(tup1, tup2, digits=10):

def truncate_tuple(tuple_or_float):
return tuple(
truncate_tuple(val)
if isinstance(val, tuple)
else int(val * power) / power
(
truncate_tuple(val)
if isinstance(val, tuple)
else int(val * power) / power
)
for val in tuple_or_float
)

Expand Down
6 changes: 4 additions & 2 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,8 +1484,10 @@ def test_compute_regular_polygon_vertices(n_sides, expected_vertices):
(50, 50, 100, 100),
0,
ValueError,
"bounding_circle should contain 2D coordinates "
"and a radius (e.g. (x, y, r) or ((x, y), r) )",
(
"bounding_circle should contain 2D coordinates "
"and a radius (e.g. (x, y, r) or ((x, y), r) )"
),
),
(
3,
Expand Down
11 changes: 6 additions & 5 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def test_render_empty(font):

def test_unicode_extended(layout_engine):
# issue #3777
text = "A\u278A\U0001F12B"
text = "A\u278a\U0001f12b"
target = "Tests/images/unicode_extended.png"

ttf = ImageFont.truetype(
Expand Down Expand Up @@ -938,7 +938,7 @@ def test_sbix(layout_engine):
im = Image.new("RGB", (400, 400), "white")
d = ImageDraw.Draw(im)

d.text((50, 50), "\uE901", font=font, embedded_color=True)
d.text((50, 50), "\ue901", font=font, embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/chromacheck-sbix.png", 1)
except OSError as e: # pragma: no cover
Expand All @@ -955,7 +955,7 @@ def test_sbix_mask(layout_engine):
im = Image.new("RGB", (400, 400), "white")
d = ImageDraw.Draw(im)

d.text((50, 50), "\uE901", (100, 0, 0), font=font)
d.text((50, 50), "\ue901", (100, 0, 0), font=font)

assert_image_similar_tofile(im, "Tests/images/chromacheck-sbix_mask.png", 1)
except OSError as e: # pragma: no cover
Expand Down Expand Up @@ -1069,8 +1069,9 @@ def test_raqm_missing_warning(monkeypatch):
FONT_PATH, FONT_SIZE, layout_engine=ImageFont.Layout.RAQM
)
assert font.layout_engine == ImageFont.Layout.BASIC
assert str(record[-1].message) == (
"Raqm layout was requested, but Raqm is not available. "
assert (
str(record[-1].message)
== "Raqm layout was requested, but Raqm is not available. "
"Falling back to basic layout."
)

Expand Down
Loading

0 comments on commit f8b357f

Please sign in to comment.