Pillow/Tests/test_file_container.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

134 lines
2.5 KiB
Python

from PIL import ContainerIO, Image
from .helper import hopper
TEST_FILE = "Tests/images/dummy.container"
def test_sanity():
dir(Image)
dir(ContainerIO)
def test_isatty():
with hopper() as im:
container = ContainerIO.ContainerIO(im, 0, 0)
assert container.isatty() is False
def test_seek_mode_0():
# Arrange
mode = 0
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
# Act
container.seek(33, mode)
container.seek(33, mode)
# Assert
assert container.tell() == 33
def test_seek_mode_1():
# Arrange
mode = 1
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
# Act
container.seek(33, mode)
container.seek(33, mode)
# Assert
assert container.tell() == 66
def test_seek_mode_2():
# Arrange
mode = 2
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
# Act
container.seek(33, mode)
container.seek(33, mode)
# Assert
assert container.tell() == 100
def test_read_n0():
# Arrange
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
# Act
container.seek(81)
data = container.read()
# Assert
assert data == "7\nThis is line 8\n"
def test_read_n():
# Arrange
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
# Act
container.seek(81)
data = container.read(3)
# Assert
assert data == "7\nT"
def test_read_eof():
# Arrange
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 22, 100)
# Act
container.seek(100)
data = container.read()
# Assert
assert data == ""
def test_readline():
# Arrange
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 0, 120)
# Act
data = container.readline()
# Assert
assert data == "This is line 1\n"
def test_readlines():
# Arrange
expected = [
"This is line 1\n",
"This is line 2\n",
"This is line 3\n",
"This is line 4\n",
"This is line 5\n",
"This is line 6\n",
"This is line 7\n",
"This is line 8\n",
]
with open(TEST_FILE) as fh:
container = ContainerIO.ContainerIO(fh, 0, 120)
# Act
data = container.readlines()
# Assert
assert data == expected