Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 4, 2022
1 parent 65edcc4 commit d968301
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Tests/test_file_ppm.py
Original file line number Diff line number Diff line change
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 All @@ -69,10 +69,10 @@ def test_header_with_comments(tmp_path):
assert im.size == (128, 128)


def test_nondecimal_header(tmp_path):
def test_non_integer_token(tmp_path):
path = str(tmp_path / "temp.ppm")
with open(path, "wb") as f:
f.write(b"P6\n128\x00")
f.write(b"P6\nTEST")

with pytest.raises(ValueError):
with Image.open(path):
Expand All @@ -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 d968301

Please sign in to comment.