Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 4, 2022
1 parent 715dcf6 commit c12ce30
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Tests/test_file_ppm.py
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c12ce30

Please sign in to comment.