Skip to content

Commit f19c347

Browse files
committed
Use fmt: skip instead of fmt: off/fmt: on
1 parent 703e5d1 commit f19c347

12 files changed

Lines changed: 121 additions & 218 deletions

Tests/test_box_blur.py

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
from PIL import Image, ImageFilter
66

77
sample = Image.new("L", (7, 5))
8-
# fmt: off
98
sample.putdata(sum([
109
[210, 50, 20, 10, 220, 230, 80],
1110
[190, 210, 20, 180, 170, 40, 110],
1211
[120, 210, 250, 60, 220, 0, 220],
1312
[220, 40, 230, 80, 130, 250, 40],
1413
[250, 0, 80, 30, 60, 20, 110],
15-
], []))
16-
# fmt: on
14+
], [])) # fmt: skip
1715

1816

1917
def test_imageops_box_blur() -> None:
@@ -85,14 +83,12 @@ def test_radius_0() -> None:
8583
sample,
8684
0,
8785
[
88-
# fmt: off
8986
[210, 50, 20, 10, 220, 230, 80],
9087
[190, 210, 20, 180, 170, 40, 110],
9188
[120, 210, 250, 60, 220, 0, 220],
9289
[220, 40, 230, 80, 130, 250, 40],
9390
[250, 0, 80, 30, 60, 20, 110],
94-
# fmt: on
95-
],
91+
], # fmt: skip
9692
)
9793

9894

@@ -101,14 +97,12 @@ def test_radius_0_02() -> None:
10197
sample,
10298
0.02,
10399
[
104-
# fmt: off
105100
[206, 55, 20, 17, 215, 223, 83],
106101
[189, 203, 31, 171, 169, 46, 110],
107102
[125, 206, 241, 69, 210, 13, 210],
108103
[215, 49, 221, 82, 131, 235, 48],
109104
[244, 7, 80, 32, 60, 27, 107],
110-
# fmt: on
111-
],
105+
], # fmt: skip
112106
delta=2,
113107
)
114108

@@ -118,14 +112,12 @@ def test_radius_0_05() -> None:
118112
sample,
119113
0.05,
120114
[
121-
# fmt: off
122115
[202, 62, 22, 27, 209, 215, 88],
123116
[188, 194, 44, 161, 168, 56, 111],
124117
[131, 201, 229, 81, 198, 31, 198],
125118
[209, 62, 209, 86, 133, 216, 59],
126119
[237, 17, 80, 36, 60, 35, 103],
127-
# fmt: on
128-
],
120+
], # fmt: skip
129121
delta=2,
130122
)
131123

@@ -135,14 +127,12 @@ def test_radius_0_1() -> None:
135127
sample,
136128
0.1,
137129
[
138-
# fmt: off
139130
[196, 72, 24, 40, 200, 203, 93],
140131
[187, 183, 62, 148, 166, 68, 111],
141132
[139, 193, 213, 96, 182, 54, 182],
142133
[201, 78, 193, 91, 133, 191, 73],
143134
[227, 31, 80, 42, 61, 47, 99],
144-
# fmt: on
145-
],
135+
], # fmt: skip
146136
delta=1,
147137
)
148138

@@ -152,14 +142,12 @@ def test_radius_0_5() -> None:
152142
sample,
153143
0.5,
154144
[
155-
# fmt: off
156145
[176, 101, 46, 83, 163, 165, 111],
157146
[176, 149, 108, 122, 144, 120, 117],
158147
[164, 171, 159, 141, 134, 119, 129],
159148
[170, 136, 133, 114, 116, 124, 109],
160149
[184, 95, 72, 70, 69, 81, 89],
161-
# fmt: on
162-
],
150+
], # fmt: skip
163151
delta=1,
164152
)
165153

@@ -169,14 +157,12 @@ def test_radius_1() -> None:
169157
sample,
170158
1,
171159
[
172-
# fmt: off
173160
[170, 109, 63, 97, 146, 153, 116],
174161
[168, 142, 112, 128, 126, 143, 121],
175162
[169, 166, 142, 149, 126, 131, 114],
176163
[159, 156, 109, 127, 94, 117, 112],
177164
[164, 128, 63, 87, 76, 89, 90],
178-
# fmt: on
179-
],
165+
], # fmt: skip
180166
delta=1,
181167
)
182168

@@ -186,14 +172,12 @@ def test_radius_1_5() -> None:
186172
sample,
187173
1.5,
188174
[
189-
# fmt: off
190175
[155, 120, 105, 112, 124, 137, 130],
191176
[160, 136, 124, 125, 127, 134, 130],
192177
[166, 147, 130, 125, 120, 121, 119],
193178
[168, 145, 119, 109, 103, 105, 110],
194179
[168, 134, 96, 85, 85, 89, 97],
195-
# fmt: on
196-
],
180+
], # fmt: skip
197181
delta=1,
198182
)
199183

@@ -203,14 +187,12 @@ def test_radius_bigger_then_half() -> None:
203187
sample,
204188
3,
205189
[
206-
# fmt: off
207190
[144, 145, 142, 128, 114, 115, 117],
208191
[148, 145, 137, 122, 109, 111, 112],
209192
[152, 145, 131, 117, 103, 107, 108],
210193
[156, 144, 126, 111, 97, 102, 103],
211194
[160, 144, 121, 106, 92, 98, 99],
212-
# fmt: on
213-
],
195+
], # fmt: skip
214196
delta=1,
215197
)
216198

@@ -225,7 +207,7 @@ def test_radius_bigger_then_width() -> None:
225207
[159, 154, 148, 142, 136, 130, 124],
226208
[160, 154, 148, 142, 137, 131, 125],
227209
[160, 155, 149, 143, 137, 131, 125],
228-
],
210+
], # fmt: skip
229211
delta=0,
230212
)
231213

@@ -240,7 +222,7 @@ def test_extreme_large_radius() -> None:
240222
[162, 162, 162, 162, 162, 162, 162],
241223
[162, 162, 162, 162, 162, 162, 162],
242224
[162, 162, 162, 162, 162, 162, 162],
243-
],
225+
], # fmt: skip
244226
delta=1,
245227
)
246228

@@ -250,14 +232,12 @@ def test_two_passes() -> None:
250232
sample,
251233
1,
252234
[
253-
# fmt: off
254235
[153, 123, 102, 109, 132, 135, 129],
255236
[159, 138, 123, 121, 133, 131, 126],
256237
[162, 147, 136, 124, 127, 121, 121],
257238
[159, 140, 125, 108, 111, 106, 108],
258239
[154, 126, 105, 87, 94, 93, 97],
259-
# fmt: on
260-
],
240+
], # fmt: skip
261241
passes=2,
262242
delta=1,
263243
)
@@ -268,14 +248,12 @@ def test_three_passes() -> None:
268248
sample,
269249
1,
270250
[
271-
# fmt: off
272251
[146, 131, 116, 118, 126, 131, 130],
273252
[151, 138, 125, 123, 126, 128, 127],
274253
[154, 143, 129, 123, 120, 120, 119],
275254
[152, 139, 122, 113, 108, 108, 108],
276255
[148, 132, 112, 102, 97, 99, 100],
277-
# fmt: on
278-
],
256+
], # fmt: skip
279257
passes=3,
280258
delta=1,
281259
)

Tests/test_color_lut.py

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,21 @@ def test_channels_order(self) -> None:
258258
)
259259

260260
# Reverse channels by splitting and using table
261-
# fmt: off
262-
assert_image_equal(
263-
Image.merge('RGB', im.split()[::-1]),
264-
im._new(im.im.color_lut_3d('RGB', Image.Resampling.BILINEAR,
265-
3, (2, 2, 2), [
266-
0, 0, 0, 0, 0, 1,
267-
0, 1, 0, 0, 1, 1,
261+
table = [
262+
0, 0, 0, 0, 0, 1,
263+
0, 1, 0, 0, 1, 1,
268264

269-
1, 0, 0, 1, 0, 1,
270-
1, 1, 0, 1, 1, 1,
271-
])))
272-
# fmt: on
265+
1, 0, 0, 1, 0, 1,
266+
1, 1, 0, 1, 1, 1,
267+
] # fmt: skip
268+
assert_image_equal(
269+
Image.merge("RGB", im.split()[::-1]),
270+
im._new(
271+
im.im.color_lut_3d(
272+
"RGB", Image.Resampling.BILINEAR, 3, (2, 2, 2), table
273+
)
274+
),
275+
)
273276

274277
def test_overflow(self) -> None:
275278
g = Image.linear_gradient("L")
@@ -282,17 +285,17 @@ def test_overflow(self) -> None:
282285
],
283286
)
284287

285-
# fmt: off
286-
transformed = im._new(im.im.color_lut_3d('RGB', Image.Resampling.BILINEAR,
287-
3, (2, 2, 2),
288-
[
289-
-1, -1, -1, 2, -1, -1,
290-
-1, 2, -1, 2, 2, -1,
291-
292-
-1, -1, 2, 2, -1, 2,
293-
-1, 2, 2, 2, 2, 2,
294-
])).load()
295-
# fmt: on
288+
table = [
289+
-1, -1, -1, 2, -1, -1,
290+
-1, 2, -1, 2, 2, -1,
291+
292+
-1, -1, 2, 2, -1, 2,
293+
-1, 2, 2, 2, 2, 2,
294+
] # fmt: skip
295+
296+
transformed = im._new(
297+
im.im.color_lut_3d("RGB", Image.Resampling.BILINEAR, 3, (2, 2, 2), table)
298+
).load()
296299
assert transformed is not None
297300
assert transformed[0, 0] == (0, 0, 255)
298301
assert transformed[50, 50] == (0, 0, 255)
@@ -303,17 +306,16 @@ def test_overflow(self) -> None:
303306
assert transformed[255, 255] == (255, 255, 0)
304307
assert transformed[205, 205] == (255, 255, 0)
305308

306-
# fmt: off
307-
transformed = im._new(im.im.color_lut_3d('RGB', Image.Resampling.BILINEAR,
308-
3, (2, 2, 2),
309-
[
310-
-3, -3, -3, 5, -3, -3,
311-
-3, 5, -3, 5, 5, -3,
312-
313-
-3, -3, 5, 5, -3, 5,
314-
-3, 5, 5, 5, 5, 5,
315-
])).load()
316-
# fmt: on
309+
table = [
310+
-3, -3, -3, 5, -3, -3,
311+
-3, 5, -3, 5, 5, -3,
312+
313+
-3, -3, 5, 5, -3, 5,
314+
-3, 5, 5, 5, 5, 5,
315+
] # fmt: skip
316+
transformed = im._new(
317+
im.im.color_lut_3d("RGB", Image.Resampling.BILINEAR, 3, (2, 2, 2), table)
318+
).load()
317319
assert transformed is not None
318320
assert transformed[0, 0] == (0, 0, 255)
319321
assert transformed[50, 50] == (0, 0, 255)
@@ -359,11 +361,10 @@ def test_convert_table(self) -> None:
359361
assert tuple(lut.size) == (2, 2, 2)
360362
assert lut.name == "Color 3D LUT"
361363

362-
# fmt: off
363364
lut = ImageFilter.Color3DLUT((2, 2, 2), [
364365
(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11),
365-
(12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23)])
366-
# fmt: on
366+
(12, 13, 14), (15, 16, 17), (18, 19, 20), (21, 22, 23),
367+
]) # fmt: skip
367368
assert tuple(lut.size) == (2, 2, 2)
368369
assert lut.table == list(range(24))
369370

@@ -484,24 +485,21 @@ def test_3_channels(self) -> None:
484485
lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))
485486
assert tuple(lut.size) == (5, 5, 5)
486487
assert lut.name == "Color 3D LUT"
487-
# fmt: off
488488
assert lut.table[:24] == [
489489
0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.5, 0.0, 0.0, 0.75, 0.0, 0.0,
490-
1.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.25, 0.25, 0.0, 0.5, 0.25, 0.0]
491-
# fmt: on
490+
1.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.25, 0.25, 0.0, 0.5, 0.25, 0.0,
491+
] # fmt: skip
492492

493493
def test_4_channels(self) -> None:
494494
lut = ImageFilter.Color3DLUT.generate(
495495
5, channels=4, callback=lambda r, g, b: (b, r, g, (r + g + b) / 2)
496496
)
497497
assert tuple(lut.size) == (5, 5, 5)
498498
assert lut.name == "Color 3D LUT"
499-
# fmt: off
500499
assert lut.table[:24] == [
501500
0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.125, 0.0, 0.5, 0.0, 0.25,
502501
0.0, 0.75, 0.0, 0.375, 0.0, 1.0, 0.0, 0.5, 0.0, 0.0, 0.25, 0.125
503-
]
504-
# fmt: on
502+
] # fmt: skip
505503

506504
def test_apply(self) -> None:
507505
lut = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))
@@ -559,11 +557,10 @@ def test_3_to_4_channels(self) -> None:
559557
assert tuple(lut.size) == tuple(source.size)
560558
assert len(lut.table) != len(source.table)
561559
assert lut.table != source.table
562-
# fmt: off
563560
assert lut.table[:16] == [
564-
0.0, 0.0, 0.0, 1, 0.2**2, 0.0, 0.0, 1,
565-
0.4**2, 0.0, 0.0, 1, 0.6**2, 0.0, 0.0, 1]
566-
# fmt: on
561+
0.0, 0.0, 0.0, 1, 0.2**2, 0.0, 0.0, 1,
562+
0.4**2, 0.0, 0.0, 1, 0.6**2, 0.0, 0.0, 1,
563+
] # fmt: skip
567564

568565
def test_4_to_3_channels(self) -> None:
569566
source = ImageFilter.Color3DLUT.generate(
@@ -575,11 +572,10 @@ def test_4_to_3_channels(self) -> None:
575572
assert tuple(lut.size) == tuple(source.size)
576573
assert len(lut.table) != len(source.table)
577574
assert lut.table != source.table
578-
# fmt: off
579575
assert lut.table[:18] == [
580-
1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 0.0, 1.0, 1.0,
581-
1.0, 0.96, 1.0, 0.75, 0.96, 1.0, 0.0, 0.96, 1.0]
582-
# fmt: on
576+
1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 0.0, 1.0, 1.0,
577+
1.0, 0.96, 1.0, 0.75, 0.96, 1.0, 0.0, 0.96, 1.0,
578+
] # fmt: skip
583579

584580
def test_4_to_4_channels(self) -> None:
585581
source = ImageFilter.Color3DLUT.generate(
@@ -589,11 +585,10 @@ def test_4_to_4_channels(self) -> None:
589585
assert tuple(lut.size) == tuple(source.size)
590586
assert len(lut.table) == len(source.table)
591587
assert lut.table != source.table
592-
# fmt: off
593588
assert lut.table[:16] == [
594-
0.0, 0.0, 0.0, 0.5, 0.2**2, 0.0, 0.0, 0.5,
595-
0.4**2, 0.0, 0.0, 0.5, 0.6**2, 0.0, 0.0, 0.5]
596-
# fmt: on
589+
0.0, 0.0, 0.0, 0.5, 0.2**2, 0.0, 0.0, 0.5,
590+
0.4**2, 0.0, 0.0, 0.5, 0.6**2, 0.0, 0.0, 0.5,
591+
] # fmt: skip
597592

598593
def test_with_normals_3_channels(self) -> None:
599594
source = ImageFilter.Color3DLUT.generate(
@@ -605,11 +600,10 @@ def test_with_normals_3_channels(self) -> None:
605600
assert tuple(lut.size) == tuple(source.size)
606601
assert len(lut.table) == len(source.table)
607602
assert lut.table != source.table
608-
# fmt: off
609603
assert lut.table[:18] == [
610604
0.0, 0.0, 0.0, 0.16, 0.0, 0.0, 0.24, 0.0, 0.0,
611-
0.24, 0.0, 0.0, 0.8 - (0.8**2), 0, 0, 0, 0, 0]
612-
# fmt: on
605+
0.24, 0.0, 0.0, 0.8 - (0.8**2), 0, 0, 0, 0, 0,
606+
] # fmt: skip
613607

614608
def test_with_normals_4_channels(self) -> None:
615609
source = ImageFilter.Color3DLUT.generate(
@@ -622,8 +616,7 @@ def test_with_normals_4_channels(self) -> None:
622616
assert tuple(lut.size) == tuple(source.size)
623617
assert len(lut.table) == len(source.table)
624618
assert lut.table != source.table
625-
# fmt: off
626619
assert lut.table[:16] == [
627620
0.0, 0.0, 0.0, 0.5, 0.25, 0.0, 0.0, 0.5,
628-
0.0, 0.0, 0.0, 0.5, 0.0, 0.16, 0.0, 0.5]
629-
# fmt: on
621+
0.0, 0.0, 0.0, 0.5, 0.0, 0.16, 0.0, 0.5,
622+
] # fmt: skip

0 commit comments

Comments
 (0)