From c12ce306441fcdda922bab020e7fd2c17c61711a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 4 Mar 2022 14:01:21 +1100 Subject: [PATCH] Fixed test --- Tests/test_file_ppm.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Tests/test_file_ppm.py b/Tests/test_file_ppm.py index fc930e31471..40ef7e43b0d 100644 --- a/Tests/test_file_ppm.py +++ b/Tests/test_file_ppm.py @@ -50,7 +50,7 @@ def test_pnm(tmp_path): assert_image_equal_tofile(im, f) -def test_not_ppm(tmp_path): +def test_magic(tmp_path): path = str(tmp_path / "temp.ppm") with open(path, "wb") as f: f.write(b"PyInvalid") @@ -82,32 +82,38 @@ def test_nondecimal_header(tmp_path): def test_token_too_long(tmp_path): path = str(tmp_path / "temp.ppm") with open(path, "wb") as f: - f.write(b"P6\n 0123456789") + f.write(b"P6\n 01234567890") - with pytest.raises(ValueError): + with pytest.raises(ValueError) as e: with Image.open(path): pass + assert str(e.value) == "Token too long in file header: b'01234567890'" + def test_too_many_colors(tmp_path): path = str(tmp_path / "temp.ppm") with open(path, "wb") as f: f.write(b"P6\n1 1\n1000\n") - with pytest.raises(ValueError): + with pytest.raises(ValueError) as e: with Image.open(path): pass + assert str(e.value) == "Too many colors for band: 1000" + def test_truncated_file(tmp_path): path = str(tmp_path / "temp.pgm") with open(path, "w") as f: f.write("P6") - with pytest.raises(ValueError): + with pytest.raises(ValueError) as e: with Image.open(path): pass + assert str(e.value) == "Reached EOF while reading header" + def test_neg_ppm(): # Storage.c accepted negative values for xsize, ysize. the