Pillow/Tests/test_file_bufrstub.py
Jon Dufresne 2c50723f14 Convert some tests to pytest style
To better follow conventional pytest style, this removes the outer
wrapper class in favor of a function for some tests. These tests were
picked as they are relatively simple and presented no barriers to a
quick port. The assert* methods are replaced with assert statements.
When necessary, a fixture is used to create a temporary directory.

This commit does not convert the entire test suite to this style as some
test classes use methods or other advanced features that are difficult
to automatically convert. The goal is to address these issues in
followup commits.

Refs #4193
2020-01-18 12:12:10 -08:00

47 lines
994 B
Python

import pytest
from PIL import BufrStubImagePlugin, Image
from .helper import hopper
TEST_FILE = "Tests/images/gfs.t06z.rassda.tm00.bufr_d"
def test_open():
# Act
with Image.open(TEST_FILE) as im:
# Assert
assert im.format == "BUFR"
# Dummy data from the stub
assert im.mode == "F"
assert im.size == (1, 1)
def test_invalid_file():
# Arrange
invalid_file = "Tests/images/flower.jpg"
# Act / Assert
with pytest.raises(SyntaxError):
BufrStubImagePlugin.BufrStubImageFile(invalid_file)
def test_load():
# Arrange
with Image.open(TEST_FILE) as im:
# Act / Assert: stub cannot load without an implemented handler
with pytest.raises(IOError):
im.load()
def test_save(tmp_path):
# Arrange
im = hopper()
tmpfile = str(tmp_path / "temp.bufr")
# Act / Assert: stub cannot save without an implemented handler
with pytest.raises(IOError):
im.save(tmpfile)