@@ -242,9 +242,10 @@ def test_should_raise(self) -> None:
242
242
class TestFlipVertically :
243
243
def test_should_flip_vertically (self ) -> None :
244
244
image = Image .from_png_file (resolve_resource_path ("image/original.png" ))
245
- image = image .flip_vertically ()
246
- image2 = Image .from_png_file (resolve_resource_path ("image/flip_vertically.png" ))
247
- assert image == image2
245
+ image2 = image .flip_vertically ()
246
+ image3 = Image .from_png_file (resolve_resource_path ("image/flip_vertically.png" ))
247
+ assert image != image2
248
+ assert image2 == image3
248
249
249
250
def test_should_be_original (self ) -> None :
250
251
image = Image .from_png_file (resolve_resource_path ("image/original.png" ))
@@ -255,16 +256,67 @@ def test_should_be_original(self) -> None:
255
256
class TestFlipHorizontally :
256
257
def test_should_flip_horizontally (self ) -> None :
257
258
image = Image .from_png_file (resolve_resource_path ("image/original.png" ))
258
- image = image .flip_horizontally ()
259
- image2 = Image .from_png_file (resolve_resource_path ("image/flip_horizontally.png" ))
260
- assert image == image2
259
+ image2 = image .flip_horizontally ()
260
+ image3 = Image .from_png_file (resolve_resource_path ("image/flip_horizontally.png" ))
261
+ assert image != image2
262
+ assert image2 == image3
261
263
262
264
def test_should_be_original (self ) -> None :
263
265
image = Image .from_png_file (resolve_resource_path ("image/original.png" ))
264
266
image2 = image .flip_horizontally ().flip_horizontally ()
265
267
assert image == image2
266
268
267
269
270
+ class TestAdjustContrast :
271
+ @pytest .mark .parametrize ("factor" , [0.75 , 5 ])
272
+ def test_should_adjust_contrast (self , factor : float ) -> None :
273
+ image = Image .from_png_file (resolve_resource_path ("image/contrast/to_adjust_contrast.png" ))
274
+ image2 = image .adjust_contrast (factor )
275
+ image3 = Image .from_png_file (
276
+ resolve_resource_path ("image/contrast/contrast_adjusted_by_" + str (factor ) + ".png" ),
277
+ )
278
+ assert image != image2
279
+ assert image2 == image3
280
+
281
+ def test_should_not_adjust_contrast (self ) -> None :
282
+ with pytest .warns (
283
+ UserWarning ,
284
+ match = "Contrast adjustment factor is 1.0, this will not make changes to the image." ,
285
+ ):
286
+ image = Image .from_png_file (resolve_resource_path ("image/contrast/to_adjust_contrast.png" ))
287
+ image2 = image .adjust_contrast (1 )
288
+ assert image == image2
289
+
290
+ def test_should_raise (self ) -> None :
291
+ image = Image .from_png_file (resolve_resource_path ("image/brightness/to_brighten.png" ))
292
+ with pytest .raises (ValueError , match = "Contrast factor has to be 0 or bigger" ):
293
+ image .adjust_contrast (- 1 )
294
+
295
+
296
+ class TestBrightness :
297
+ @pytest .mark .parametrize ("factor" , [0.5 , 10 ])
298
+ def test_should_adjust_brightness (self , factor : float ) -> None :
299
+ image = Image .from_png_file (resolve_resource_path ("image/brightness/to_brighten.png" ))
300
+ image2 = image .adjust_brightness (factor )
301
+ image3 = Image .from_png_file (resolve_resource_path ("image/brightness/brightened_by_" + str (factor ) + ".png" ))
302
+ assert image != image2
303
+ assert image2 == image3
304
+
305
+ def test_should_not_brighten (self ) -> None :
306
+ with pytest .warns (
307
+ UserWarning ,
308
+ match = "Brightness adjustment factor is 1.0, this will not make changes to the image." ,
309
+ ):
310
+ image = Image .from_png_file (resolve_resource_path ("image/brightness/to_brighten.png" ))
311
+ image2 = image .adjust_brightness (1 )
312
+ assert image == image2
313
+
314
+ def test_should_raise (self ) -> None :
315
+ image = Image .from_png_file (resolve_resource_path ("image/brightness/to_brighten.png" ))
316
+ with pytest .raises (ValueError , match = "Brightness factor has to be 0 or bigger" ):
317
+ image .adjust_brightness (- 1 )
318
+
319
+
268
320
class TestInvertColors :
269
321
def test_should_invert_colors_png (self ) -> None :
270
322
image = Image .from_png_file (resolve_resource_path ("image/original.png" ))
0 commit comments