2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2024-01-26 20:17:13 +03:00
|
|
|
from pathlib import Path, PurePath
|
2024-01-26 20:15:19 +03:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
import pytest
|
2020-09-01 20:16:46 +03:00
|
|
|
|
2014-07-06 02:47:30 +04:00
|
|
|
from PIL import _util
|
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2024-01-26 20:17:13 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"test_path", ["filename.ext", Path("filename.ext"), PurePath("filename.ext")]
|
|
|
|
)
|
2024-02-20 07:41:20 +03:00
|
|
|
def test_is_path(test_path: str | Path | PurePath) -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
# Act
|
2022-04-10 21:20:48 +03:00
|
|
|
it_is = _util.is_path(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
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_is_not_path(tmp_path: Path) -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
# 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
|
2022-04-10 21:20:48 +03:00
|
|
|
it_is_not = _util.is_path(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
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_deferred_error() -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
# Arrange
|
2014-07-06 02:47:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
# Act
|
2023-12-27 02:40:55 +03:00
|
|
|
thing = _util.DeferredError.new(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
|