Refactor test_pickle_image to use pytest.mark.parametrize

This commit is contained in:
Hugo 2020-04-16 11:31:28 +03:00
parent 97280a045c
commit 53a85f2a69

View File

@ -1,11 +1,14 @@
import pickle import pickle
import pytest
from PIL import Image from PIL import Image
def helper_pickle_file(tmp_path, pickle, protocol=0, mode=None): def helper_pickle_file(
tmp_path, pickle, protocol=0, test_file="Tests/images/hopper.jpg", mode=None
):
# Arrange # Arrange
with Image.open("Tests/images/hopper.jpg") as im: with Image.open(test_file) as im:
filename = str(tmp_path / "temp.pkl") filename = str(tmp_path / "temp.pkl")
if mode: if mode:
im = im.convert(mode) im = im.convert(mode)
@ -35,11 +38,14 @@ def helper_pickle_string(
assert im == loaded_im assert im == loaded_im
def test_pickle_image(tmp_path): @pytest.mark.parametrize(
"test_file", ["Tests/images/hopper.jpg"],
)
def test_pickle_image(test_file, tmp_path):
# Act / Assert # Act / Assert
for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1): for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1):
helper_pickle_string(pickle, protocol) helper_pickle_string(pickle, protocol, test_file)
helper_pickle_file(tmp_path, pickle, protocol) helper_pickle_file(tmp_path, pickle, protocol, test_file)
def test_pickle_p_mode(): def test_pickle_p_mode():