mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
2c50723f14
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
73 lines
1.1 KiB
Python
73 lines
1.1 KiB
Python
import pytest
|
|
from PIL import _util
|
|
|
|
|
|
def test_is_path():
|
|
# Arrange
|
|
fp = "filename.ext"
|
|
|
|
# Act
|
|
it_is = _util.isPath(fp)
|
|
|
|
# Assert
|
|
assert it_is
|
|
|
|
|
|
@pytest.mark.skipif(not _util.py36, reason="os.path support for Paths added in 3.6")
|
|
def test_path_obj_is_path():
|
|
# Arrange
|
|
from pathlib import Path
|
|
|
|
test_path = Path("filename.ext")
|
|
|
|
# Act
|
|
it_is = _util.isPath(test_path)
|
|
|
|
# Assert
|
|
assert it_is
|
|
|
|
|
|
def test_is_not_path(tmp_path):
|
|
# Arrange
|
|
with (tmp_path / "temp.ext").open("w") as fp:
|
|
pass
|
|
|
|
# Act
|
|
it_is_not = _util.isPath(fp)
|
|
|
|
# Assert
|
|
assert not it_is_not
|
|
|
|
|
|
def test_is_directory():
|
|
# Arrange
|
|
directory = "Tests"
|
|
|
|
# Act
|
|
it_is = _util.isDirectory(directory)
|
|
|
|
# Assert
|
|
assert it_is
|
|
|
|
|
|
def test_is_not_directory():
|
|
# Arrange
|
|
text = "abc"
|
|
|
|
# Act
|
|
it_is_not = _util.isDirectory(text)
|
|
|
|
# Assert
|
|
assert not it_is_not
|
|
|
|
|
|
def test_deferred_error():
|
|
# Arrange
|
|
|
|
# Act
|
|
thing = _util.deferred_error(ValueError("Some error text"))
|
|
|
|
# Assert
|
|
with pytest.raises(ValueError):
|
|
thing.some_attr
|