2019-11-04 01:18:55 +03:00
|
|
|
import pytest
|
2020-08-07 13:28:33 +03:00
|
|
|
|
2014-07-06 02:47:30 +04:00
|
|
|
from PIL import _util
|
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
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
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
test_path = Path("filename.ext")
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Act
|
|
|
|
it_is = _util.isPath(test_path)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Assert
|
|
|
|
assert it_is
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-06-13 18:54:46 +03:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
def test_is_not_path(tmp_path):
|
|
|
|
# Arrange
|
|
|
|
with (tmp_path / "temp.ext").open("w") as fp:
|
|
|
|
pass
|
2019-01-28 20:14:42 +03:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Act
|
|
|
|
it_is_not = _util.isPath(fp)
|
2019-01-28 20:14:42 +03:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Assert
|
|
|
|
assert not it_is_not
|
2019-01-28 20:14:42 +03:00
|
|
|
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
def test_is_directory():
|
|
|
|
# Arrange
|
|
|
|
directory = "Tests"
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Act
|
|
|
|
it_is = _util.isDirectory(directory)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Assert
|
|
|
|
assert it_is
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
def test_is_not_directory():
|
|
|
|
# Arrange
|
|
|
|
text = "abc"
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Act
|
|
|
|
it_is_not = _util.isDirectory(text)
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Assert
|
|
|
|
assert not it_is_not
|
2014-07-06 02:47:30 +04:00
|
|
|
|
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
def test_deferred_error():
|
|
|
|
# Arrange
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Act
|
|
|
|
thing = _util.deferred_error(ValueError("Some error text"))
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Assert
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
thing.some_attr
|